DO WHILE Loops

DO WHILE loops in a flowchart appear as follows:

dfhrx004

As REXX instructions, the flowchart example looks like:
DO WHILE  expression    /* expression must be true */
   instruction(s)
END

Use a DO WHILE loop when you want to execute the loop while a condition is true. DO WHILE tests the condition at the top of the loop. If the condition is initially false, the language processor never executes the loop.

You can use a DO WHILE loop instead of the DO FOREVER loop in the example of using the LEAVE Instruction. However, you need to initialize the loop with a first case so the condition can be tested before you get into the loop. Notice the first case initialization in the first PULL of the following example.
Figure 1. Example Using DO WHILE
/******************************** REXX *******************************/
/* This program uses a DO WHILE loop to send a string to a           */
/* user-written function for processing.                             */
/*********************************************************************/
  PULL string                       /* Gets string from input stream */
  DO WHILE string \= 'QUIT'
        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
        PULL string
  END
  SAY 'Program run complete.'

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/dfhrx00047.html