if

Conditionally executes a BLOCK of PSL code

Syntax

 if ( expression )
	{ BLOCK }

 if ( expression )
	{ BLOCK } 
else
	{ BLOCK } 

if ( expression )
	{ BLOCK } 
elsif ( expression )
	{ BLOCK } 
else
	{ BLOCK }

Parameters

ParameterDefinition
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:

 if (x > 10) \{
x = 10; # don't let x get bigger than 10
}

if . . . else statement:

 if (x == 0) \{
# do something} else 
# x != 0
# do something else
}


if . . . elsif . . . else statement:

 if (x == 0) 
# do something
} elsif (x == 1) {
# do something else
} else {
# x != 0 && x != 1
# do something else
}

Where to go from here

PSL Statements

Was this page helpful? Yes No Submitting... Thank you

Comments