Programming Guide |
Execute different statements based on the value of an expression
switchtestExpression
casecaseExpression
[, caseExpression
] ...
statementBlock
[casecaseExpression
[, caseExpression
] ...
statementBlock
]
...
[defaultdefaultStatementBlock
]
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 withtestExpression
. If they are equal, thestatementBlock
following the case statement is executedstatementBlock
- One or more statements that JPL executes if the preceding case statement finds a match. If
statement
Block
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. IfdefaultStatementBlock
has more than one statement, enclose the block with open and close blocking characters{}
on the lines before and after it.
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 totestExpression
; 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 matchtestExpression
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.
//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.'
}