if, else, elseif, endif

Purpose

Controls program flow with conditional branching.

Format

if scalar_expression;
    ...
elseif scalar_expression;
    ...
elseif scalar_expression;
    ...
else;
    ...
endif;

Examples

if x < 0;
   y = -1;
elseif x > 0;
   y = 1;
else;
   y = 0;
endif;

Remarks

The scalar_expression is any expression that returns a scalar. It is TRUE if it is not zero, and FALSE if it is zero.

A list of statements is any set of GAUSS statements.

GAUSS will test the expression after the if, else, elseif, endif statement. If it is TRUE (nonzero), then the first list of statements is executed. If it is FALSE (zero), then GAUSS will move to the expression after the first elseif statement, if there is one, and test it. It will keep testing expressions and will execute the first list of statements that corresponds to a TRUE expression. If no expression is TRUE, then the list of statements following the else statement is executed. After the appropriate list of statements is executed, the program will go to the statement following the endif and continue on.

if, else, elseif, endif statements can be nested.

One endif is required per if, else, elseif, endif statement. If an else statement is used, there may be only one per if, else, elseif, endif statement. There may be as many elseif’s as are required. There need not be any elseif’s or any else statement within an if, else, elseif, endif statement.

Note the semicolon after the else statement.