Conditional Loops; Do While Loops - IBM TSO/E REXX User Manual

Table of Contents

Advertisement

Using Looping Instructions

Conditional Loops

There are two types of conditional loops, DO WHILE and DO UNTIL. Both types of
loops are controlled by one or more expressions. However, DO WHILE loops test
the expression before the loop executes the first time and repeat only when the
expression is true. DO UNTIL loops test the expression after the loop executes at
least once and repeat only when the expression is false.

DO WHILE Loops

DO WHILE loops in a flowchart appear as follows:
DO WHILE
END
As REXX instructions, the flowchart example looks like:
DO WHILE expression
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 loop is never executed.
You can use a DO WHILE loop instead of the DO FOREVER loop in the example
using the "LEAVE Instruction" on page 50. 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 beginning three lines of the following example.
52
z/OS V1R1.0 TSO/E REXX User's Guide
regardless of whether the user enters "quit", "QUIT", or "Quit", the language
processor translates the input to uppercase before comparing it to "QUIT".
expression
False
instruction(s)
Example Using DO WHILE
/******************************** REXX *****************************/
/* This exec uses a DO WHILE loop to send data sets to the system */
/* printer.
/*******************************************************************/
SAY 'Enter the name of a data set to print.'
SAY 'If there are no data sets, enter QUIT.'
PULL dataset_name
DO WHILE dataset_name \= 'QUIT'
"PRINTDS DA("dataset_name")"
SAY dataset_name 'printed.'
SAY 'Enter the name of the next data set.'
SAY 'When there are no more data sets, enter QUIT.'
PULL dataset_name
END
SAY 'Good-bye.'
True
instruction(s)
/* expression must be true */
*/

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents