Counting DO-Loop

There are two forms of loops, the counting loop and the general loop. The syntax of the counting loop is the following:

DO control-var = initial-value, final-value, [step-size]
   statements
END DO
where control-var is an INTEGER variable, initial-value and final-value are two INTEGER expressions, and step-size is also an INTEGER expression whose value cannot be zero. Note that step-size is optional. If it is omitted, the default value is 1. statements is a sequence of statements and is usually referred to as the body of the DO-loop. You can use any executable statement within a DO-loop, including IF-THEN-ELSE-END IF and even another DO-loop.

The following are a few simple examples:

The meaning of this counting-loop goes as follows:

Examples

Frequently Used Loop Tricks

In addition to repeatedly processing some data as shown above, the DO-loop has some other uses as presented in the following examples:

Some Helpful Notes

There are certain things you should know about DO-loops.