DO UNTIL expression /* expression must be false */
instruction(s)
END
Use DO UNTIL loops when a condition is not true and you want to execute the loop
until the condition is true. The DO UNTIL loop tests the condition at the end of the
loop and repeats only when the condition is false. Otherwise the loop executes
once and ends. For example:
Example Using DO UNTIL
/******************************** REXX *****************************/
/* This exec uses a DO UNTIL loop to ask for a password. If the */
/* password is incorrect three times, the loop ends. */
/*******************************************************************/
password = 'abracadabra'
time = 0
DO UNTIL (answer = password) | (time = 3)
SAY 'What is the password?'
PULL answer
time = time + 1
END
Exercise - Using a DO UNTIL Loop
Change the exec in the previous exercise, “Exercise - Using a DO WHILE Loop” on
page 53, 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.'
Using Looping Instructions
54
z/OS V1R1.0 TSO/E REXX User’s Guide