Executes the provided statements while incrementing or decrementing a counter
variable at each iteration.
The loop may be terminated without regard to the counter by using the
BREAKstatement. The current iteration of the loop can be abandoned and the next iteration of the loop started by using the
- variable-name: variable name
The name of the counter variable. The variable name must begin with an at sign (
@), dollar sign (
$), or colon (
:). The variable need not be previously declared; the
FORstatement acts as a variable declaration if needed. This variable will receive an integer value that changes with each iteration of the loop.
- first-number: integer
The value of the counter variable on the first iteration of the loop.
- last-number: integer
The loop stops if the counter steps past this value.
- step: integer (optional)
The number to add to the counter variable on each iteration. If first-number ≤ last-number then the default step is 1, otherwise the default step is -1.
- statement: statement
The statements to execute on each iteration of the loop. If more than one statement is desired, the
ENDkeywords must be used.
-- Prints the numbers: 1, 2, 3, 4, 5.
FOR @i = 1 TO 5
-- Prints the numbers: 5, 4, 3, 2, 1.
FOR @i = 5 TO 1
-- Prints the numbers: 1, 3, 5, 9.
FOR @i = 1 TO 10 STEP 2