OS/2 Procedures Language 2/REXX


Inf-HTML [About][Toc][Index] 0.9b (c) 1995 Peter Childs


Automating Repetitive Tasks - Using Loops


If you want to repeat several instructions in a procedure, you can use a 
loop.  Loops often are used in programming because they condense many 
lines of instructions into a group that can be run more than once.  Loops 
make your procedures more concise, and with a loop, you can continue 
asking a user for input until the correct answer is given. 
With loops, you can keep adding or subtracting numbers until you want to 
stop.  You can define how many times you want a procedure to handle an 
operation.  You will see how to use simple loops to repeat instructions in 
a procedure. 
The two types of loops you may find useful are repetitive loops and 
conditional loops.  Loops begin with a DO instruction and end with the END 
instruction.  The following is a list of topics in this section: 
 DO num loop                   Repeats the loop a fixed number of times. 
 DO i=1 to 10 loop             Numbers each pass through the loop.  Sets a 
                               starting and ending value for the variable. 
                               
 DO WHILE                      Tests for true or false at the top of the 
                               loop. Repeats the loop if true.  If false, 
                               continues processing after END. 
 Do UNTIL                      Tests for true or false at the bottom of 
                               the loop. Repeats the loop if false.  If 
                               true, continues processing after END. 
 LEAVE                         Causes the interpreter to exit a loop. 
 DO FOREVER                    Repeats instructions until the user says to 
                               quit. 
 Getting out of loops          Requires that you press the Ctrl+Break 
                               keys. 
 Parsing words                 Assigns a different variable to each word 
                               in a group. 
   

Inf-HTML End Run - Successful