if
Conditionally executes a BLOCK of PSL code
Syntax
{ BLOCK }
if ( expression )
{ BLOCK }
else
{ BLOCK }
if ( expression )
{ BLOCK }
elsif ( expression )
{ BLOCK }
else
{ BLOCK }
Parameters
Parameter | Definition |
---|---|
expression | PSL statement that evaluates an expression and returns either TRUE or FALSE |
BLOCK | one or more PSL statements that are executed once in accordance with the evaluation of the if or elsif expressions |
Description
The if statement conditionally executes a BLOCK of PSL code. The if statement is straightforward. Since a statement BLOCK is always bounded by braces, there is no ambiguity about which if, elsif, and else statement applies to the block of code.
Examples
The following examples highlight the use of if, elsif, and else:
if statement:
x = 10; # don't let x get bigger than 10
}
if . . . else statement:
# do something} else
# x != 0
# do something else
}
if . . . elsif . . . else statement:
# do something
} elsif (x == 1) {
# do something else
} else {
# x != 0 && x != 1
# do something else
}
Where to go from here