do and end. You determine the terminating conditions. You can execute for statements for each instance of a class of items, for each item or value in a list or array, or based on the value of a numeric expression.
for statement with the each quantifier to execute a sequence of statements once for each instance of a class of items. The syntax is:
for local-name = each generic-reference-expression
do
statement [; ...]
end
|
Specifies any generic reference to an item or value that G2 iterates over in the set.
| |
|
Any procedure or action statement.
|
for V = each valve
do
change the icon-color of V to red;
end
for V = each valve connected to tank-1
do
change the icon-color of V to red;
end
tank-1 change color.
for counter = numeric-expression-1 {to | down to} numeric-expression-2
[by increment]
do
statement [; ...]
end
Each time G2 executes the
for statement, it compares the value of the counter with the values of numeric-expression-1 and numeric-expression-2. If the counter value is equal to or within the range specified by numeric-expression-1 and numeric-expression-2, G2 executes the statements contained in the body. to or down to. By default, the counter is incremented by 1 (if you specify to) or decremented by 1 (if you specify down to). You can also specify a different increment or decrement by using the optional by increment phrase. for statement.
Note: You can also transfer control out of the for loop by using an exit if statement. See exit if for more information.
for loop-counter =1 to 100 by 2
do
.
.
.
end
for will be performed when loop-counter equals 99.
for each statement does not in itself cause a procedure to enter a wait state. However, executing a statement of the form for each ... do in parallel causes a procedure to enter a wait state between the iteration which launches the parallel iterations and the entrance to each parallel iteration. This enables an arbitrary number of threads to be launched through the iteration without risk of the procedure timing out. For information about wait states see Allowing Other Processing. The
do in parallel statement is described under do in parallel.