Controlling the flow within a program

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.

About this task

The REXX instructions that alter the sequential execution of a REXX program can be classified as follows:

Conditional instructions
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
Looping instructions
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
Interrupt instructions
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