IBM SC34-5764-01 Manual page 65

Cics transaction server for vse/esa
Table of Contents

Advertisement

DO WHILE Loops
DO WHILE loops in a flowchart appear as follows:
DO WHILE
expression
False
END
As REXX instructions, the flowchart example looks like:
DO WHILE expression
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 language processor never executes the
loop.
You can use a DO WHILE loop instead of the DO FOREVER loop in the example of using the LEAVE
instruction on page 41. 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 first PULL of the following
example.
/******************************** REXX *******************************/
/* This program uses a DO WHILE loop to send a string to a
/* user-written function for processing.
/*********************************************************************/
PULL string
DO WHILE string \= 'QUIT'
result = process(string)
IF result = 0 THEN SAY "Processing complete for string:" string
ELSE SAY "Processing failed for string:" string
PULL string
END
SAY 'Program run complete.'
Figure 22. Example Using DO WHILE
Exercise - Using a DO WHILE Loop
Write a program with a DO WHILE loop that uses as input a list of responses about whether passengers
on a commuter airline want a window seat. The flight has 8 passengers and 4 window seats. Discontinue
the loop when all the window seats are taken. After the loop ends, produce the number of window seats
taken and the number of responses processed.
ANSWER
True
instruction(s)
/* expression must be true */
/* Gets string from input stream */
/* Calls a user-written function */
/* to do processing on string.
Control Flow within a Program
*/
*/
*/
Chapter 4. Controlling the Flow within a program
43

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Rexx

Table of Contents