z/OS TSO/E REXX User's Guide
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


Exercise - Using a DO UNTIL Loop

z/OS TSO/E REXX User's Guide
SA32-0982-00

Change the exec in the previous exercise, Exercise - Using a DO WHILE Loop, from a DO WHILE to a DO UNTIL loop and achieve the same results. Remember that DO WHILE loops check for true expressions and DO UNTIL loops check for false expressions, which means their logical operators are often reversed.

ANSWER

Possible Solution

/******************************** REXX *****************************/
/* This exec uses a DO UNTIL loop to keep track of window seats in */
/* an 8-seat commuter airline.                                     */
/*******************************************************************/

  window_seats = 0        /* Initialize window seats to 0          */
  passenger = 0           /* Initialize passengers to 0            */

  DO UNTIL (passenger >= 8) | (window_seats = 4)

   /****************************************************************/
   /* Continue until you have questioned all 8 passengers or until */
   /* all the window seats are taken.                              */
   /****************************************************************/

    SAY 'Do you want a window seat?  Please answer Y or N.'
    PULL answer
    passenger = passenger + 1
                        /* Increase the number of passengers by 1  */
    IF answer = 'Y' THEN
       window_seats = window_seats + 1
                       /* Increase the number of window seats by 1 */
    ELSE NOP
  END
  SAY window_seats 'window seats were assigned.'
  SAY passenger 'passengers were questioned.'

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014