The For statement is used to repeat a loop based on a counter.
Syntax
For variable = number
To number
Step number
Do
... ;
Od;
For variable = number is the counter and initial value.To number is upper limit.Step number is optionally, step size.... ; This is code that will be repeated.
Variable must be declared as a Number. The initial value, limit and step value are calculated once before the loop is executed the first time. At the end of each loop variable is incremented with the Step value. It is possible (but not advisable) to modify the variable within the loop.
If the Step keyword is omitted the step value will default to 1.
The Do … Od loop will be executed while:
Variable is smaller or equal to the To value if the Step value is greater or equal to 0.
Variable is larger or equal to the To value if the Step value is negative.
The Break command can be used to terminate the loop unconditionally.
Example
This example locates the / in a path by 'walking' through it using the substring function.
Parameter Text Path;
Var Number Count;
For Count = 1 To length(Path) Do
If substring (Path, Count, 1) = "\" Then
Break;
Fi;
Od;
Parameter Text Path; Input path must be passed to this script.Var Number Count; This is the count variable needed in the statement For is and must be declared before this statement.
The location of the "\" in Path is stored in Count and can be used in the remainder of the script because Count is declared outside the For loop which means that its scope is not limited to the For loop. Although this is a valid example the filename manipulation methods provided in ITP/Server are more convenient.