Rexx Programming/How to Rexx/loops

Loops are control structures that allow sections of code to be executed repeatedly according to the controlling conditions of the loop. The rexx scripting language supports both iterative loops and conditional loops.

Iterative LoopsEdit

An iterative loop repeatedly executes a set of instructions as the iterator steps through a series of values. Types of iterative loops include forloops and foreach loops. The following is a traditional example of an iterative for loop:

do l = 1 to 10
  say l
end

In the above example, the say block runs ten times and the iterator variable $l, increments on each consecutive loop.

Conditional LoopsEdit

A conditionalloop tests for a condition around the loop, and repeatedly executes a block of instructions whilst the condition is true. Types of conditional loops include while loops and until loops.

l = 0 do while l <= 10

 say l
 l = l + 1

end

Loop ControlsEdit

Both iterative loops and conditional loops can be controlled by loop modifier statements, such as leave, iterate and signal (Do we also have next, last and redo?). These allow normal flow of execution within a loop to be restarted or terminated.

Nested LoopsEdit

The rexx scripting language allows nested loop structures to be used. These consist of one or more loops that are nested within other loops.

Last modified on 18 May 2011, at 23:42