Core.Actions.Loop.ForEachLoop
Classification
Name | ForeachLoop |
Short Description | Loop that is iterated for each element of a collection. |
Class | Action |
Extension | OTX Core library |
Group | Core related actions |
Exceptions | ConcurrentModificationException |
Checker Rules | Core_Chk014 Core_Chk056 |
Standard Compliant | Yes |
OTL Syntax
foreach (IntegerTerm in Collection) : LoopName
{
...
}
Description
The OTX ForEachLoop activity contains a sequence of activities that are executed repeatedly for all elements of a List or Map. It is used to iterate through collections and to obtain the desired information. She should be not used, to change the contents of the collection to avoid unpredictable side effects.
The Collection is represented by an expression, see property Collection, which will be calculated at the beginning of the loop. The loop for each element of the collection is then iterated through. The current element of the collection can be accessed through the Locator Variable. It contains the corresponding Index for a List and for a Map the respective Key.
The collection is of type List, iterate the iterations in the Order. The loop starts with the first item (index = 0) and ending with the last element. Collections of type map, the order is indeterminate.
The Locator Variable is inside and outside of the loop that is valid. After the last iteration, it contains the index or key of the last item in the collection.
The loop can be exited about the activities of Break, Return, or Throw. The Continue activity stops the current iteration and continues with the next iteration, without having to leave the loop.
Properties
Name | Data Type | Class | Default | Cardinality | Description |
Locator | Integer | Variable | - | [1] | See Locator variable of the loop of the type integer in a list or string in a map, collection property. |
Collection | - | Term | - | [1] | Collection of type List or Map is iterated through which within the loop |
OTL Examples
List<Integer> Collection1 = {1, 2, 3};
Integer Locator1;
foreach (Locator1 in Collection1) : ForEachLoop1
{
Hmi.ConfirmDialog(Conversion.ToString(Collection1[Locator1]), null, @MessageTypes:INFO, null);
}