Combining Types Of Loops; Nested Do Loops - IBM SC34-5764-01 Manual

Cics transaction server for vse/esa
Table of Contents

Advertisement

Control Flow within a Program
ANSWER
/******************************** REXX *******************************/
/* This program 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 while the program has not yet read the responses of
/* all 8 passengers and while all the window seats are not taken. */
/******************************************************************/
PULL window
passenger = passenger + 1 /* Increase number of passengers by 1 */
IF window = 'Y' THEN
window_seats = window_seats + 1 /* Increase window seats by 1 */
ELSE NOP
END
SAY window_seats 'window seats were assigned.'
SAY passenger 'passengers were questioned.'
Figure 25. Possible Solution

Combining Types of Loops

You can combine repetitive and conditional loops to create a compound loop. The following loop is set to
repeat 10 times while the quantity is less than 50, at which point it stops.
quantity = 20
DO number = 1 TO 10 WHILE quantity < 50
quantity = quantity + number
SAY 'Quantity = 'quantity ' (Loop 'number')'
END
The result of this example is as follows:
Quantity = 21
(Loop 1)
Quantity = 23
(Loop 2)
Quantity = 26
(Loop 3)
Quantity = 30
(Loop 4)
Quantity = 35
(Loop 5)
Quantity = 41
(Loop 6)
Quantity = 48
(Loop 7)
Quantity = 56
(Loop 8)
You can substitute a DO UNTIL loop, change the comparison operator from < to >, and get the same
results.
quantity = 20
DO number = 1 TO 10 UNTIL quantity > 50
quantity = quantity + number
SAY 'Quantity = 'quantity ' (Loop 'number')'
END

Nested DO Loops

Like nested IF...THEN...ELSE instructions, DO loops can contain other DO loops. A simple example
follows:
46
CICS TS for VSE/ESA: REXX Guide
/* Initialize window seats to 0 */
/* Initialize passengers to 0
/* Gets "Y" or "N" from input stream */
*/
*/
*/
*/

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Rexx

Table of Contents