Arbortext Command Language > Commands > for
  
for
for ( expression1; expression2; expression3 ) {command-list}
for ( $variable in $array ) {command-list}
The first form of this command evaluates expression1 and then executes the listed commands while expression2 is true. At the end of each iteration, executes expression3. This is equivalent to:
expression1 ; while (expression2) { command-list ; expression3 ;}
The second form of this command executes listed commands with the variable set to each subscript of the array. The subscripts are returned in order (from the lowest to the highest) for a normal array. If the array is associative, the subscripts are returned in arbitrary order. The command list must not contain another for ($variable in $array) statement over the same array.
Examples
# Display each of the variables in the
#array "$includes" on std out.
for ($i = 1; $i <= count($includes); $i++) {
eval "[$i], $includes[$i]" output=-;
}
# This alias creates a list of all valid tags
# in the current document:
tag_names($tags);
$list = " "
for ($i in $tags) {
$list .= delete($tags[$i]) . " "
}
Related Topics
If, while, for, switch
Functions as expressions and commands
Command variables
Logical expressions
while command