Chapter 4. Controlling the Flow within a program
This chapter introduces instructions that alter the sequential execution of a program and demonstrates
how to use those instructions.
Conditional, Looping, and Interrupt Instructions
Generally, when a program 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 change the order of execution within a program by using REXX instructions that cause the
language processor to skip some instructions, repeat others, or transfer control to another part of the
program. These REXX instructions can be classified as follows:
v Conditional instructions 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 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 repetitor...END
DO WHILE expression...END
DO UNTIL expression...END
v Interrupt instructions tell the language processor to leave the program entirely or leave one part of the
program and go to another part, either permanently or temporarily. The REXX interrupt instructions are:
EXIT
SIGNAL label
CALL label...RETURN
Using Conditional Instructions
There are two types of conditional instructions:
v IF...THEN...ELSE can direct the execution of a program to one of two choices.
v SELECT WHEN...OTHERWISE...END can direct the execution to one of many choices.
IF...THEN...ELSE Instructions
The examples of IF...THEN...ELSE instructions in previous chapters demonstrate the two-choice selection.
In a flow chart, this appears as follows:
expression
instruction instruction
Tr ueFalse
ELSE THEN
© Copyright IBM Corp. 1992, 2009 33