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.'