Programming Guide



switch

Execute different statements based on the value of an expression

Synopsis

switch testExpression

case caseExpression[, caseExpression] ...
statementBlock

[case caseExpression[, caseExpression] ...
statementBlock]
...
[default
defaultStatementBlock]

Arguments

testExpression
Specifies a value to be tested by case statements that follow the switch statement. testExpression can be any expression. For more information on expressions, refer to "Expressions" in Application Development Guide.

caseExpression
Each caseExpression is evaluated and compared with testExpression. If they are equal, the statementBlock following the case statement is executed

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

defaultStatementBlock
defaultStatementBlock is or more statements that JPL executes if none of the preceding case statements find a match. If defaultStatementBlock has more than one statement, enclose the block with open and close blocking characters {} on the lines before and after it.

Description

The switch command does conditional execution of other JPL statements. It is new to Panther 5.40. Each switch can be followed by one or more case commands to create a chain of conditional processing. JPL checks the value of each caseExpression in the chain until finds a value that is equal to testExpression; JPL then executes the statement block that follows the case command and exits the chain. If none of the case expressions in a switch chain match testExpression and if the chain ends with the default command, JPL executes the following statement block. If the switch chain omits a default command, JPL simply exits the chain and continues execution with the next statement after it.

Example

//Determine a person's sex, based on personal title.
switch title

case 'MR'
sex = 'Male'
case 'MS', 'MRS', 'MISS'
sex = 'Female'
default
{
sex = 'Unknown'
msg err_reset 'Please supply a title.'
}