DO FOREVER Loops

Sometimes you might want to write an infinite loop purposely; for instance, in a program that reads records from a file until it reaches the end of the file. You can use the EXIT instruction to end an infinite loop when a condition is met, as in the following example. More about the EXIT instruction appears in section EXIT Instruction.
Figure 1. Example Using a DO FOREVER Loop
/******************************* 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

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 LEAVE instruction. The following topic describes this.


Reference Reference

Feedback


Timestamp icon Last updated: Tuesday, 7 January 2014


http://pic.dhe.ibm.com/infocenter/cicsts/v5r1/topic/com.ibm.cics.rexx.doc//dfhrx/dfhrx00043.html