Exercise - Using A Do Until Loop - IBM TSO/E REXX User Manual

Table of Contents

Advertisement

Using Looping Instructions
DO UNTIL expression
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:

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
54
z/OS V1R1.0 TSO/E REXX User's Guide
instruction(s)
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
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
passenger = 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
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.'
/* expression must be false */
/* Initialize window seats to 0
/* Initialize passengers to 0
/* Increase the number of passengers by 1 */
*/
*/
*/
*/
*/
*/

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents