For Each Value…End Statement (FPScript)
Repeats a series of statements and in the process traverses all values of a data set.
Syntax
For Each Value Y[[, X], Z] In Data Set Do
[Statements]
End
The syntax of the For Each Value...End statement consists of the following elements:
Element |
Description |
---|---|
Y, X, Z |
Variables that adopt the values of the data set. You can omit the variables to the right. You do not have to declare the variables with Dim. |
DataSet |
The data set whose values are to be taken. The data set cannot be a scalar value. |
Statements |
One or more statements that are executed for each value in Data Set. |
Remarks
The For Each Value block is executed if there is at least one value in Data Set. The loop is repeated for all values in Data Set where X, Y and Z adopt the values from the data set. The program then leaves the loop and continues the execution with the statement that follows the End statement.
The columns of a two dimensional data set are traversed one after another. If a variable is used for a component that is not present in the data set, then it receives increasing 64-bit integral values that start with 0.
If a traversed component of Data Set is a quantity, then its unit is used in the corresponding control variable.
Note: You should avoid loops over individual values of a data set, if possible. FPScript makes it possible for you to calculate complete data sets in one statement. Loops can usually be replaced by functions for event isolation in conjunction with the Index operator. The For Each Value...End loop is the fastest FPScript loop.
Available in
FlexPro View, Basic, Professional, Developer Suite
Example
The following example collects all values in a signal that are greater than or equal to 5.0:
Arguments Signal
Dim SY, SX
For Each Value Y, X In Signal Do
If Y >= 5 Then
SY := Y
SX := X
End
End
Signal(SY, SX)
Using event isolation, the example above can be written much more easily and efficiently:
Arguments Signal
Signal[ValuesAboveLevel(Signal, 5)]
See Also
For Each Column...End Statement