Control Structures
ForEachItem()
This function emulates a loop construct that runs across all elements in an array. This array also represents the return value, with values that may have been modified in the loop.
Parameter | Data Type | Description |
|---|---|---|
1 | Array | Array across which elements are to be iterated |
2 | (variable) | Macro expression executed for each element in the array The value of the current element and its position number are addressed in this expression via the variables |
Examples
For example, the following macro increases the value by 1 for each of the 3 array elements:
ForEach([1, 2, 3], @Value = @Value + 1)
In this case, the modified array [2, 3, 4] is returned as the overall result.
The operation does not necessarily have to affect the array elements themselves; it might also modify another field. If the "target field" has the initial value 0, this value will increase to 6 after macro execution, but the array will remain unchanged:
ForEach([1, 2, 3], @TargetField = @TargetField + @Value)
If()
This function emulates an If-Then control structure. A condition is first evaluated and, depending on the result of this condition, a specified macro expression is either executed or not. The return type varies depending on the result of the executed macro expression.
If the expression is not executed, no return value will be returned. A target field will thus not returned a result value, but will retain its current value.
Parameter | Data Type | Description |
|---|---|---|
1 | Bool | Macro expression representing the condition |
2 | (variable) | Macro expression that will be executed if the condition is valid |
Examples
If(TRUE, "OK") returns "OK".
If(FALSE, "OK") does not return a value.
If(TRUE, @Test = "OK") sets the value of the Test field to "OK".
If(FALSE, @Test = "OK") does not change the Test field.
IfElse()
This function emulates an If-Then-Else control structure. A condition is evaluated and, depending on the result of the condition, one of two specified macro expressions will be executed.
The return type will vary depending on the result of the macro expressions.
Parameter | Data Type | Description |
|---|---|---|
1 | Bool | Macro expression representing the condition |
2 | (variable) | Macro expression that will be executed if the condition is valid |
3 | (variable) | Macro expression that will be executed if the condition is invalid |
Examples
IfElse(FALSE, "OK", "NotOK") returns "NotOK".
IfElse(TRUE, @OK = TRUE, @NotOK = TRUE) sets the value of the OK field to TRUE.
Switch()
This function emulates a switch case control structure. The parameter list is of variable length and consists alternately of a condition to be evaluated and an associated macro expression. The macro expression will be executed only if the condition is valid; then the macro execution will be terminated, otherwise the next condition will be evaluated.
The return type will vary depending on the result of the macro expressions.
If none of the conditions are valid, no return value will be returned. Thus, no result value will be assigned to the target field. Instead, it will retain its current value.
Parameter | Data Type | Description |
|---|---|---|
1 | Bool | First macro expression representing a condition |
2 | (variable) | Macro expression to be executed if the previous condition is valid |
… | ||
n-1 | Bool | Last macro expression representing a condition |
n | (variable) | Macro expression to be executed if the preceeding condition is valid |
Examples
Switch(FALSE, "Case1", TRUE, "Case2") returns "Case2".
Switch(FALSE, "Case1", FALSE, "Case2") does not return a value.
Switch(FALSE, @Test = "Case1", TRUE, @Test = "Case2") sets the value of the Test field to "Case2".
Switch(FALSE, @Test = "Case1", FALSE, @Test = "Case2") does not change the Test field.