This example sends strings to a user-written function for processing and then issues a message that the

processing completed successfully or failed. When the input string is a blank, the loop ends and so does

the program. You can also end the loop without ending the program by using the LEAVEinstruction. The

following topic describes this.

LEAVE Instruction

The LEAVE instruction causes an immediate exit from a repetitive loop. Control goes to the instruction

following the END keyword of the loop. An example of using the LEAVE instruction follows:

ITERATE Instruction

The ITERATE instruction stops execution from within the loop and passes control to the DO instruction at

the top of the loop. Depending on the type of DO instruction, the language processor increases and tests

a control variable or tests a condition to determine whether to repeat the loop. Like LEAVE, ITERATEis

used within the loop.

DO count=1TO10
IF count = 8
THEN
ITERATE
ELSE
SAY 'Number' count
END

This example results in a list of numbers from 1 to 10 with the exception of number 8.

/******************************* REXX ********************************/
/* This program processes strings until the value of a string is */
/* a null string. */
/*********************************************************************/
DO FOREVER
PULL string /* Gets string from input stream */
IF string = '' THEN
PULL file_name
IF file_name = '' THEN
EXIT
ELSE
DO
result = process(string) /* Calls a user-written function */
/* to do processing on string. */
IF result = 0 THEN SAY "Processing complete for string:" string
ELSE SAY "Processing failed for string:" string
END
END
Figure 20. Example Using a DO FOREVER Loop
/******************************** REXX *******************************/
/* This program uses the LEAVE instruction to exit from a DO */
/* FOREVER loop. */
/*********************************************************************/
DO FOREVER
PULL string /* Gets string from input stream */
IF string = 'QUIT' then
LEAVE
ELSE
DO
result = process(string) /* Calls a user-written function */
/* to do processing on string. */
IF result = 0 THEN SAY "Processing complete for string:" string
ELSE SAY "Processing failed for string:" string
END
END
SAY 'Program run complete.'
Figure 21. Example Using the LEAVE Instruction
Control Flow within a Program
Chapter 4. Controlling the Flow within a program 41