for Statement

A for loop lets you run a section of code a specific number of times. The loop variable counts up or down with each execution of the loop. The loop body is repeatedly executed until the loop variable reaches the end number.

Syntax

for <VARIABLE> = <START> to <END> [step <AMOUNT>]
<BODY>
next

Usage

The following example loops 10 times and prints the loop variable at each iteration.
for i = 1 to 10
print i
next
The exit for statement can be used to exit a loop before reaching the end number. This example prints the numbers 1 to 4, because the exit for statement exits the loop when the loop variable i is 5.
for i = 1 to 10
if i = 5 then
exit for
end if
print i
next