|
|
|
|
|
- Syntax 1: Iterating over elements in the array
- Syntax 2: Iterating over values of elements in the array
FOR EACH/FOR ALL statement (browse of arrays) In french: POUR TOUT / POUR TOUS
FOR EACH is used to perform different types of browse on the arrays: - Browsing the array elements,
- Browsing the values of array elements.
Note: The FOR EACH, FOR ALL statements are accepted. The FOR EACH statement will be used in this documentation but it can be replaced with FOR ALL. The FOR EACH statement can also be used to browse the .Net objects that implement the IEnumerable interface. // Browse the elements found in an array of reals and calculate the sum // Fill the array ArrCalc is array of 3 reals ArrCalc[1] = 12.5 ArrCalc[2] = 10 ArrCalc[3] = 7.5 // Calculate the sum TotalSum is real FOR EACH AnElement OF ArrCalc TotalSum += AnElement END
Syntax
Browsing the array elements Hide the details
FOR EACH [ELEMENT] <Variable> [, <Key> [, <Counter>]] OF <Array> [WHERE <Condition>] [<Direction>] ... END
<FOR EACH [ELEMENT]>: Marks the beginning of the statement block. The ELEMENT keyword is optional. <Variable>: Variable whose type is identical to the type of the array elements. For the arrays of classes, the variable must be a Dynamic Class variable. There is no need to declare this variable. <Key>: Key of element browsed. This key depends on the element being looped through:- One-dimensional array: Index of the element in the array.
- Array with two or more dimensions: Counter starting at 1
There is no need to declare this variable. <Counter>: Integer variable containing the number of iterations. There is no need to declare this variable. <Array>: Array to browse. <Condition>:
<Direction>: Optional indicator for the iteration direction: | | FromBeginning (default value) | Browse the array from the first element to the last one. | FromEnd | Browse the array from the last element to the first one. |
Browsing the values of array elements Hide the details
FOR EACH [ELEMENT] <Value> OF <Array> [WHERE <Condition>] [<Direction>] ... END
<FOR EACH ELEMENT>: Marks the beginning of the statement block. The ELEMENT keyword is optional. <Value>: Variable whose type is compatible with the array elements. There is no need to declare this variable. <Array>: Array to browse. <Condition>:
<Direction>: Optional indicator for the iteration direction: | | FromBeginning (default value) | Browse the array from the first element to the last one. | FromEnd | Browse the array from the last element to the first one. |
Remarks Syntax 1: Iterating over elements in the array For each iteration, <Variable> directly refers to the current element in the array. If the value of <Variable> is modified, the current element in the array is modified. When exiting from the loop (standard exit or via the BREAK statement), the value of the last element read is assigned to <Variable> but <Variable> does not directly refer to the array element anymore. All types of arrays are available: automatic, fixed, dynamic. The arrays can have several dimensions. The behavior is undefined if the number of elements is modified in the browse loop. Syntax 2: Iterating over values of elements in the array For each iteration, the value of the element browsed is assigned to the <Value> variable. If the value of <Value> is modified, the current element in the array is not modified. All types of arrays are available: automatic, fixed, dynamic. The arrays can have several dimensions. The behavior is undefined if the number of elements is modified in the browse loop.
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|