Note: This operation has been deprecated. For new workflows, please use the ForLoop operation. For more information see Looping
Basic Usage
A counted loop operation allows you to execute something a set number of times. It is very similar in concept to a C++ for
loop with an integer counter. The analogous code would be something like this (assuming the Step value is positive):
for (
int i = startValue;
i <= endValue;
i += stepValue)
{
}
double i
Definition: opencljuliaset.cpp:45
The workspace equivalent looks something like this:
Example 1: A basic counted loop
In the above example, the loop to be executed a set number of times is fairly obvious, going from the "Counted loop" operation, through the "Iteration workspace" and back to the "Counted
loop" operation again. The "Iteration workspace" will execute once for each iteration of the loop. Unlike ordinary workspace operations, however, the CountedLoop has some fairly unique logic for how it updates its inputs and outputs. This is necessary to make the loop behave like a loop and still be able to connect to other workspace entities. For a counted loop operation, the following rules define the behaviour:
- To make the operation execute the loop, you must request its Dependencies output. The Counter value output is special and belongs to the looping part of the logic, so requesting it will not execute the whole loop.
- When the counted loop is executed, it performs the follow sequence:
-
Set the Counter value (at both the input and output) to the Start value. Make both become not up to date, then mark them as both up to date again. This generally causes all operations between the Counter value output and the Iteration dependency input to become not up to date. If it doesn't, the loop will not operate correctly.
-
If the Counter value is beyond the End value, the loop is complete.
-
Bring the Iteration dependency input up to date. This should result in one iteration of the loop.
-
Add the Step value to the Counter value (again, at both the input and output), flip the up to date status of the Counter value input and output again and go to step 2.
- If you want to re-run the loop again, you need to force the Dependencies input to be not up to date. This will have the effect of resetting the operation so that it will start from the Start value again.
- The path around the loop must be contained to the current workspace or below. While operations within the loop are allowed to request values from a DataSource, you must ensure that doing so won't result in this same workspace having one of its outputs being requested (that would imply that the whole workspace is part of the loop, which is not permitted).