The if statement

The if statement can be used to conditionally execute statements. The following is an example of an if construct.

if a==b
display a,b
c->d
monitor d
endif

In this example, the statements between the if and endif statements will be executed only if a is equal to b. The operand of an if statement may be an arbitrary expression. If the expression evaluates to non-zero, it is considered to be a true result, and the statements between the if and endif statements will be executed. If the expression evaluates to zero, it is considered to be a false result and the statements will be skipped. Every if statement must have a corresponding endif statement. If statements may be nested arbitrarily.

The else statement can be used to cause statements to be executed when a condition is false. The following example illustrates.

if a==b
display a,b
c->d
monitor d
else
display c,d
x->y
monitor z
endif

In this example a and b will be displayed if a and b are equal, and c and d will be displayed otherwise.

The elif statement can be used to construct multi-way conditionals. It can be used to simplify the construction of else-if conditionals. The following two constructs will produce the same results.

if a==b
display a,b
else
if a==c
display a,c
else
display x,y
endif
endif

if a==b
display a,b
elif a==c
display a,c
else
display x,y
endif

Any number of elif statements may be included in a single if construct. The final else statement is optional. A single endif statement terminates the entire construct.