Chapter 4. Controlling the Flow Within an Exec
Using Conditional Instructions ...................42
IF/THEN/ELSE Instructions ...................42
Nested IF/THEN/ELSE Instructions ................43
Exercise - Using the IF/THEN/ELSE Instruction ...........44
SELECT/WHEN/OTHERWISE/END Instruction ............44
Exercises - Using the SELECT/WHEN/OTHERWISE/END Instruction . . . 46
Using Looping Instructions ....................47
Repetitive Loops .......................47
Infinite Loops .......................48
DO FOREVER Loops ....................49
LEAVE Instruction ......................50
ITERATE Instruction .....................50
Exercises - Using Loops ...................51
Conditional Loops .......................52
DO WHILE Loops ......................52
Exercise - Using a DO WHILE Loop ...............53
DO UNTIL Loops ......................53
Exercise - Using a DO UNTIL Loop ...............54
Combining Types of Loops ...................55
Nested DO Loops .......................55
Exercises - Combining Loops .................56
Using Interrupt Instructions ....................56
EXIT Instruction .......................57
CALL/RETURN Instructions ...................57
SIGNAL Instruction ......................58
This chapter introduces instructions that alter the sequential execution of an exec
and demonstrates how those instructions are used.
Generally when an exec runs, one instruction after another executes, starting with
the first and ending with the last. The language processor, unless told otherwise,
executes instructions sequentially.
You can alter the order of execution within an exec by using specific REXX
instructions that cause the language processor to skip some instructions, repeat
others, or jump to another part of the exec. These specific REXX instructions can
be classified as follows:
v Conditional instructions, which set up at least one condition in the form of an
expression. If the condition is true, the language processor selects the path
following that condition. Otherwise the language processor selects another path.
The REXX conditional instructions are:
IF expression/THEN/ELSE
SELECT/WHEN expression/OTHERWISE/END.
v Looping instructions, which tell the language processor to repeat a set of
instructions. A loop can repeat a specified number of times or it can use a
condition to control repeating. REXX looping instructions are:
DO expression/END
DO FOREVER/END
DO WHILE expression=true/END
DO UNTIL expression=true/END
© Copyright IBM Corp. 1988, 2001 41