The For Construct

The For construct is a simple statement which executes a piece of code a set number of times. It also changes the value of a variable on each iteration through the loop.

It looks like this....

for n = 1 to 10 step 1
next n

Initialliy, n is set to 1. This is because 1 is the first number n should be set to inside the loop.

The code inside the loop is executed until n contains the value 10. This is specified after the to statement.

Each iteration through the loop n is increased by 1. This is specifed after the step command. This number can also be a negative number. If no step value is specifed e.g.

for n = 1 to 10
next n

then it is assumed that the step has a value of 1.

Table of contents