FOR - repeat one or more statements, using a counter.

$*$FOR
may take several forms. In the form
$*$FOR var=start,end : statement
the variable "var" is assigned the value of the expression "start". (This must be a numeric expression.) EXEC then executes the statement following the colon. This statement may be a TSS command or EXEC directive. After executing the statement, EXEC increments "var" by 1. If "var" is less than the value of the expression "end", EXEC executes the statement again. EXEC keeps repeating and incrementing "var" by 1 until "var" is greater than "end"; note that EXEC executes the statement when "var" equals "end".

$*$FOR can also take the form

$*$FOR var=start,end,incr : statement
In this case, "incr" is an expression giving the amount to increment "var". EXEC increments "var" by this amount each time through the loop until "var" is greater than "end" if "incr" is positive, and less than "end" if "incr" is negative.

$*$FOR can also take either of the forms

$*$FOR var = expr;expr;expr;... : statement
or
$*$FOR var = expr expr expr ... : statement
EXEC evaluates the first expression and assigns the value to "var". It then executes the given statement. After the statement is finished, EXEC evaluates the next expression in the list and assigns the value to "var"; it then executes the statement again. In this way, EXEC executes the statement for each expression in the expression list.

You can have an expression list that combines forms, as in

$*$FOR a = 1,10;"abc";20,10,-1 : statement
This repeats the given statement with "a" taking values from 1 to 10, then the value "abc", then the values going backwards from 20 to 10.

In this form of $*$FOR, the statement is evaluated when the line is read. This means that a statement like

$*$FOR I=1,10,2 : echo #I
the #I will be immediately evaluated as the statement is read (giving you whatever value the variable I has at the time). This is seldom what you want. Typically therefore, you must "escape" the # character by typing two of them, as in
$*$FOR I=1,10,2 : echo ##I
When this statement is read, it is evaluated as "echo #I" so that the variable is incremented appropriately at each repetition.

$*$FOR can also have any of the forms

$*$FOR var=start,end
    statements
$*$EndFor
 
$*$FOR var=start,end,incr
    statements
$*$EndFor
 
$*$FOR var=expr;expr;...
    statements
$*$EndFor
 
$*$FOR var=expr expr expr ...
    statements
$*$EndFor
These let you repeat several statements instead of just one. Statement blocks may contain $*$FOR constructs of their own (nested FORs). See the section "Input Expansion" in the main explain file "expl exec" for more details that pertain to $*$FOR statements.

Copyright © 2000, Thinkage Ltd.