SELECT WHEN...OTHERWISE...END Instruction
To select one of any number of choices, use the SELECT WHEN...OTHERWISE...END instruction. In a
flowchart it appears as follows:
False
False
THEN
WHEN
WHEN
WHEN
OTHERWISE
END
Tr ue
instruction
THEN
Tr ue
instruction
THEN
Tr ue
instruction
instruction(s)
SELECT
expression
expression
expression
As a REXX instruction, the flowchart example looks like:
SELECT
WHEN expression THEN instruction
WHEN expression THEN instruction
WHEN expression THEN instruction
:
:
OTHERWISE
instruction(s)
END
The language processor scans the WHEN clauses starting at the beginning until it finds a true expression.
After it finds a true expression, it ignores all other possibilities, even though they might also be true. If no
WHEN expressions are true, it processes the instructions following the OTHERWISE clause.
As with IF...THEN...ELSE, when you have more than one instruction for a possible path, begin the set of
instructions with a DO and end them with an END. However, if more than one instruction follows the
OTHERWISE keyword, DO and END are not necessary.
Control Flow within a Program
Chapter 4. Controlling the Flow within a program 37