Usage: FOREACH <structure> <variable> { <commands> }
FE (<list>) <variable> { <commands> }
FOR (<commence>, <evaluation>, <iteration>) { <commands> }
This causes <commands> to be executed once for each
element in the structure. The aliases inside the {}
are not expanded until execution unless the leading {
is quoted like \{
Here are a couple examples of basic foreach commands.
assign blue.1 one
assign blue.2 two
assign blue.3 three
foreach blue ii { echo $ii $blue[$ii] }
will return
1 one
2 two
3 three
FOREACH can also be imbedded such as in the following example.
assign blue.1.1 one one
assign blue.1.2 one two
assign blue.2.1 two one
assign blue.2.2 two two
alias showblue {
foreach blue ii
{
foreach blue.$ii jj
{
echo $ii $jj $blue[$ii][$jj]
}
}
}
And /showblue returns..
1 1 one one
1 2 one two
2 1 two one
2 2 two two
Another example using FE:
assign blue one two three
alias showblue {
fe ($blue) ii {
echo $ii
}
}
And /showblue returns:
one
two
three
And an example for FOR:
for (@count=1,count<5,@count++) {
echo count is now $count
}
Output:
count is now 1
count is now 2
count is now 3
count is now 4

Note:
When using this format the {} in the foreach must be on separate
lines by themselves. This is true for IF and WHILE as well.

Notice that variable names 'ii' and 'jj' were used. Any name can
be used for the index but keep in mind that single letter vars can
interfere with the built in single char vars. See ALIAS special

See Also:
expressions
ALIAS special

Back to help index