Select when...otherwise...end instruction – IBM SC34-5764-01 User Manual

Page 59

Advertising
background image

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

True

instruction

THEN

True

instruction

THEN

True

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

Advertising