Workspace 6.21.5
Executing a loop

Basic Usage

A WhileLoop operation allows you to execute a sequence of operations multiple times. It is similar in concept to a C++ do-while loop with a guarding Boolean condition. The analogous code would be something like this:

if("Enable loop")
{
do
{
// Optionally: use "First iteration" to do any initial processing
// execute a sequence of operations
// Optionally: on a specific iteration set "Keep looping" to false to terminate the looping
} while("Enable loop" && "Keep looping");
}

The minimal Workspace equivalent looks something like this:

Example: A basic while loop

In the above example, the loop will continue to execute while the Enable loop and Keep looping inputs are both checked, to stop the workflow just uncheck one of these inputs.

The simple logic of how a WhileLoop works:

  1. The operation(s) connected between the WhileLoop's Iteration Dependencies output and its Iteration Dependencies input form the body of the loop. In our example there are only two operations in the body of the Loop, a LogText and a Pause .
  2. To make the WhileLoop operation execute the loop, you must request its Dependencies output, in our example this is the Workspace Output labelled While loop dependency .
  3. When the WhileLoop needs to execute it will initially look only at the Enable loop input and if it is set to true then it will set the First iteration output to true and reset its Iteration Dependencies . This will cause the downstream operations that make up the Loop to be marked out-of-date.
  4. The operations in the Loop will then be executed.
  5. In our example, the loop will execute until the last operation, the Pause operation, completes and resets the WhileLoop's Iteration Dependencies input.
  6. At this point the WhileLoop operation checks both its "Enable loop" and "Keep looping" inputs and either starts the next iteration if both are true or ceases looping if either (or both) are false.
  7. If you want to re-run the loop again, you only need to change any of its inputs, or reset the Dependencies input.
Note
A connection to Enable loop can only come from outside the loop-body. If an attempt to execute a WhileLoop when the Enable loop input is connected to an output from inside the loop body is made then this will fail with an error something like: ERROR: Detected what looks like a circular dependency.
A connection to Keep looping can come from either inside or outside the loop-body - either way will work. However, be careful with the case that the condition is outside the loop-body, as there is potential here for infinite loop scenarios.
Even if the Keep looping input is initially set to false you will still get one iteration of the loop.