ProvideX V8.20 > Language Reference > 2. Directives
133
FOR..NEXT Directive
             Loop While Incrementing
Format
1. Conventional Syntax: FOR var=first TO last [STEP val]
..NEXT [var]
2. Simplified Syntax: FOR var ..NEXT [var]
Where:
first
Initial value of the variable var. Numeric expression.
last
Ending value of the variable var (value that ends the loop when achieved).
Numeric expression.
NEXT Directive to end the loop. Optional var must match current FOR var.
TO
Keyword required for Format 1, not case-sensitive.
STEP
Optional keyword, not case-sensitive. Sets specific increment/decrement
value (default is 1).
val
Optional value by which the variable will be incremented/decremented
with each pass through the loop. The default is 1.
var
Numeric control variable to be incremented/decremented with each pass
through the loop.
Description
Use the FOR directive (either conventional or simplified iteration format) to define
the start of a repetitive loop of instructions in a program. If you specify a variable
with a NEXT directive, it must match the variable in the FOR directive. The NEXT
directive can appear anywhere in the program except where it would be executed
inside another FOR/NEXT loop, a GOSUB/RETURN routine, a WHILE/WEND loop,
or a REPEAT/UNTIL loop. The control variable can be omitted from the NEXT
directive because the increment/decrement of the FOR var is assumed automatically.
However, the NEXT var is useful for readability purposes, especially if it appears
within a nested loop structure.
Use the EXITTO directive to halt a FOR/NEXT loop without performing all iterations.
When ProvideX executes an EXITTO directive, it removes the top entry from the
FOR/NEXT stack and ends the current FOR/NEXT loop.
Format 1: For Loop, Conventional Syntax
FOR var=first TO last [STEP val]
..NEXT [var]
When using conventional syntax, the keyword TO is required in order to define first
and last values in the loop.