foreach statement
for statement
while statement
repeat statement
The foreach, for and repeat statements provide for iteration.
The foreach statement is designed for iterating over a series of words. In this example, i is iterated over the list of all the files in the Samples directory. Each one, in turn, is tested to see if it’s executable (i.e., has a .csh, .cmd, .bat, .exe or .com extension or is a valid binary executable.)
The for statement provides more traditional iteration over numerical values. If you specify a range (e.g., 1 to 3) but don’t specify the increment, 1 is assumed. Although this example shows iteration over integer values, floating point values are equally acceptable.
You can also iterate over a list of ranges or individual values. The to and by clauses may be specified in either order.
The while statement works in the traditional manner, iterating so long as the while condition is true. This example keeps popping up through the various levels of parent directories until it reaches the root. fullpath is one of the builtin procedures; it return the fully-qualified pathname of its argument. Notice that fullpath is invoked in three different ways: on line 421, as if it were a command, on 422 in more conventional procedure syntax and on 423, where it’s substituted in as if it were a variable.
The repeat statement has two forms. In the short form, a numeric constant (not an expression) specifies the number of times to execute the statement following on the same line.
In the long form, repeat provides the more conventional repeat structure, iterating until some exit condition satisfied.
foreach, for, while and repeat
Miscellaneous statements
Expression operators
Wildcard characters
Tutorial: Expressions
Tutorial: Wildcarding