SWITCH
PLBCMP Only
The SWITCH instruction provides a multi-way branch that allows a series of conditional statements to evaluate multiple conditions. The instruction uses the following format:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Where:
label
Optional. A Program Execution Label.
source
Required. A Character Variable, Numeric Variable, an Expression, or a decimal constant value.
case
Required. A Character String Variable, Numeric Variable, an Expression, or a decimal constant value matched or compared with the first operand in the SWITCH statement.
Flags Affected: NONE
Note the following:
The SWITCH statement defines the beginning of the construct and requires one operand.
No executable statements are allowed between the SWITCH and the first CASE statement.
The ENDSWITCH statement defines the end of the construct.
At least one CASE statement must be specified between the SWITCH and the ENDSWITCH statements. Any number of additional CASE statements may be used.
An optional DEFAULT statement may be specified after the last CASE statement but before the ENDSWITCH. Only one DEFAULT statement is allowed.
The operand specified for the SWITCH statement defines a selection criteria used when evaluating each CASE statement.
Each CASE statement operand is compared or matched to the SWITCH operand.
The data type for a CASE operand must be the same as the corresponding operand for the SWITCH statement.
Each CASE statement operand may be specified as more than one selection criteria, and if so the keyword 'OR' must separate the selection criteria items. In this case, either selection criteria item matching the SWITCH operand satisfies the selection criteria.
If the CASE operand is equal to the SWITCH operand, the CASE statement is determined to satisfy the selection criteria and the statements following the CASE statement are processed up to the next CASE, DEFAULT or ENDSWITCH, whichever comes first. Only the statements for the first matching CASE statement are processed, and all others are ignored.
Nesting of the SWITCH construct is allowed up to thirty-two (32) levels.
See Also: Example Code, Program Control Instructions
![]() |