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 Format
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 Format statement is executed. After the
appropriate list of statements is executed, the program will go to the
statement following the Format and continue on.
if, else, elseif, endif statements can be nested.
One Format is required per if, else, elseif, endif statement. If an Format statement is used, there may be only one per if, else, elseif, endif statement. There may be as many Format’s as are required. There need not be any Format’s or any Format statement within an if, else, elseif, endif statement.
Note the semicolon after the Format statement.
See also
keywords do while, do until, do while, do until