This statement allows you step through the a set of statements a certain number of times.
The statement has 2 main sections:
for
section specifies the start and end values, and optionally, the step value. The for
loop will start at the start value, and end at the end value minus the step value. If a step value is not given it is assumed to be 1
.Here are some examples:
for i=1 to 10 { trace(i); }This will print out:
1 2 3 4 5 6 7 8 9This one steps downwards:
for i=10 to 0 step -1 { trace(i); }This will print out:
10 9 8 7 6 5 4 3 2 1