Mark Hobley
LOOPS



Loops

Loops are control structures that allow sections of code to be executed repeatedly according to the controlling conditions defined for the loop. Most programming languages support both iterative loops and conditional loops.

Iterative 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 loop:

 for l = 1 to 10
print l
next l
In the above example, the print block runs ten times and the iterator variable $l, increments on each consecutive loop.

Conditional Loops

A conditional loop 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
while l <= 10
print l
l = l + 1
wend

Loop Controls

Both iterative loops and conditional loops can be controlled by loop modifier statements, such as next, last and redo. These allow normal flow of execution within a loop to be restarted or terminated.

Nested Loops

Many programming languages allows nested loop structures to be used. These consist of one or more loops that are nested within other loops.