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.
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.
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
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.
The rexx scripting language allows nested loop structures to be used. These consist of one or more loops that are nested within other loops.