Programming Guide



if

Conditionally executes one or more JPL statements

Synopsis

if logicalExpr
statementBlock

[else if logicalExpr
statementBlock]
...
[else
statementBlock]

Arguments

logicalExpr
Specifies the condition under which JPL executes statementBlock, where logicalExpr can be any logical expression. For more information on logical expression construction, refer to "Logical Expressions" in Application Development Guide.

statementBlock
One or more statements that JPL executes if the preceding logicalExpr evaluates to true. If statementBlock has more than one statement, enclose the block with open and close blocking characters {} on the lines before and after.

else if logicalExpr
Optionally specifies the statement block to execute if all previous if and else if conditions evaluate to false and logicalExpr evaluates to true.

else
Optionally specifies the statement block to execute if all previous if and else if conditions evaluate to false. Each else must be paired with an if statement and follow all else if statements associated with that if.

Description

The if command specifies conditional execution of other JPL statements. Each if can be followed by one or more else if commands to create a chain of conditional processing. JPL executes each if and else if in the chain until it evaluates one of the conditions to true; JPL then executes the statement block and exits the chain. If all conditions in an if chain evaluate to false and the chain ends with an else command, JPL executes the else statement block. If the if chain omits an else command, JPL simply exits the chain and continues module execution.

Example

//Determine a person's sex, based on personal title.
if title == 'MR'
sex = 'Male'
else if title == 'MS'
sex = 'Female'
else if title == 'MRS'
sex = 'Female'
else if title == 'MISS'
sex = 'Female'
else
{
sex = 'Unknown'
msg err_reset 'Please supply a title.'
}