Infinite Loops - IBM TSO/E REXX User Manual

Table of Contents

Advertisement

Using Looping Instructions
A variable that controls the number of times a loop repeats is called a control
variable. Unless you specify otherwise, the control variable increases by 1 each
time the loop repeats.
DO number = 1 TO 5
END
This example results in five lines of Hello! preceded by the number of the loop.
The number increases at the bottom of the loop and is tested at the top.
You can change the increment of the control variable with the keyword BY as
follows:
DO number = 1 TO 10 BY 2
END
This example has results similar to the previous example except the loops are
numbered in increments of two.

Infinite Loops

What happens when the control variable of a loop cannot attain the last number?
For example, in the following exec segment, count does not increase beyond 1.
DO count = 1 to 10
END
The result is called an infinite loop because count alternates between 1 and 0 and
an endless number of lines saying Number 1 appear on the screen.
48
z/OS V1R1.0 TSO/E REXX User's Guide
SAY 'Loop' number
SAY 'Hello!'
SAY 'Dropped out of the loop when number reached' number
Loop 1
Hello!
Loop 2
Hello!
Loop 3
Hello!
Loop 4
Hello!
Loop 5
Hello!
Dropped out of the loop when number reached 6
SAY 'Loop' number
SAY 'Hello!'
SAY 'Dropped out of the loop when number reached' number
Loop 1
Hello!
Loop 3
Hello!
Loop 5
Hello!
Loop 7
Hello!
Loop 9
Hello!
Dropped out of the loop when number reached 11
SAY 'Number' count
count = count - 1

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents