Format:
if condition then [ ] indicates that this part is optional.
statements;
[elseif condition then
statements;]
[else
statements;]
endif;
Description:
The if statement executes different statements based on the value of "condition". The condition following the if command is evaluated. If the condition is true, then the statements following it are executed and execution moves to the first statement after the endif keyword. If the condition is false, execution moves to the first elseif keyword or the else keyword (if there are no elseif keywords).
The elseif blocks are evaluated in the same way as the first if block. When CSPro finds a condition that is true it executes the statements following it and moves to the first statement after the endif keyword. If all the conditions are false, the statements following the else keyword are executed. If none of the conditions are true and there is no else keyword, execution moves to the first statement after the endif keyword without the execution of any statements within the if statement.
Every if statement must contain an endif keyword. However, if multiple elseif keywords are nested within an if block, they may be terminated with a single endif keyword. The statements within the if statement can be any number of CSPro statements. If a condition contains an inequality (e.g., >, <, >=, <=) and one of the values tested in the inequality is a special value (e.g., MISSING, REFUSED, NOTAPPL, or DEFAULT), the result of the condition is false and execution skips to the statement following the else.
Example:
if X = 3 then
z = 6;
elseif x in 4:5 or y in 7:9,12 then
z = 7;
else
z = 8;
endif;