If
If
is used to perform tests in a script.
If NUMERIC_EXPRESSIONlist_of_instructions_ifEndifIf NUMERIC_EXPRESSIONlist_of_instructions_ifElselist_of_instructions_elseEndifIf NUMERIC_EXPRESSIONlist_of_instructions_ifElsif NUMERIC_EXPRESSIONlist_of_instructions_elsifEndifIf NUMERIC_EXPRESSIONlist_of_instructions_ifElsif NUMERIC_EXPRESSIONlist_of_instructions_elsifElselist_of_instructions_elseEndif
# First exampleIf I=1# Line executed if I=1Else# Line executed if I is not equal to 1Endif# Second exampleIf find(CHOICE,"YES","SURELY","CERTAINLY","PERHAPS","MAYBE","POSSIBLY")# If CHOICE is in the values listed, find returns the rank in the list and this branch will be executedElse# If CHOICE is out of the list, find returns 0 and this branch will be executedEndif# More complex alternativeIf I=1# Line executed if I=1Elsif I=2 or I=1# Line executed only if I=2 (the first branch has been executed if I=1)Elsif func STRANGE(I)=3# Line executed if the condition is fulfilled. Take care, I might have been modified by Funprog STRANGEElsif I=1 or I=3# Line executed if I was not equal to 1 and 2, if the condition STRANGE(I)=3 was false,# buf if I is equal to 1 or 3 after execution of STRANGE SubprogElse# Line executed in all other casesEndif
If the value of NUMERIC_EXPRESSION is nonzero, list_of_instructions_if
is executed.
If optional Elsif conditions are present, the condition found after every Elsif is evaluated, and the list_of_instructions_elsif
found after the first Elsif for which NUMERIC_EXPRESSION is nonzero will be executed.
If the optional Else is present, list_of_instructions_else
is executed if the value of the expression in all the Elsif conditions is zero.
NUMERIC_EXPRESSION must be of arithmetic or logical type.
In all forms of the If
statement, the expression is evaluated, including all unexpected results if a Funprog is called. After execution of the instructions found in the right branch of the If/Elsif/Else/Endif nesting structure, the instruction following the Endif instruction is executed, except if a Break, End, or Goto function is executed in the branch.