DO WHILE Loops

DO WHILE loops in a flowchart appear as follows:

IKJC3004
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 loop is never executed.

You can use a DO WHILE loop instead of the DO FOREVER loop in the example 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 beginning three lines of the following example.

Example Using DO WHILE

/******************************** REXX *****************************/
/* This exec uses a DO WHILE loop to send data sets to the system  */
/* printer.                                                        */
/*******************************************************************/
  SAY 'Enter the name of a data set to print.'
  SAY 'If there are no data sets, enter QUIT.'
  PULL dataset_name
  DO WHILE dataset_name \= 'QUIT'
     "PRINTDS DA("dataset_name")"
     SAY dataset_name 'printed.'
     SAY 'Enter the name of the next data set.'
     SAY 'When there are no more data sets, enter QUIT.'
     PULL dataset_name
  END
  SAY 'Good-bye.'