Build a program containing a loop¶
What you will learn
- The loop flow functionality
- Use the
Do Whilecontrol block in your program
- Connect input and outputs
In the following example we are creating a program which runs a loop that executes the "wait" command five times and then stops. This tutorial uses a
Do While function block connected with a condition value in order to explain the basic concepts of linking and program flow. Alternatively, you may also achieve the same functionality using the
For Loop. But for learning purposes, this tutorial shows how to manually simulate a For Loop. For Loop usage is described here.
Create a new program.
Loop Do Whilefrom Control Structures library to the builder canvas.
Compare Integerfrom Basic Function Blocks library inside the Loop.
Waitfrom Basic Function Blocks library inside the Loop and after the counter.
Waitfunction block and set waiting time to 0.5 seconds.
Compare Integerfunction block as shown in the picture.
![Set parameter of the loop](images/loop_with_counter/b_1.png)
Link operand 1 to the output of the loop cycle counter by pressing thelink button and selecting the cycle count output of the
![Set the loop condition](images/loop_with_counter/b_2.png)
![Select the counter as a reference](images/loop_with_counter/b_3.png)
![Save the loop](images/loop_with_counter/b_4.png)
Assign the other operand to 5 (this is the maximum number of runs).
Assign to the Condition operator a '<' sign.
After the desired number of iterations in the loop, the 'Loop Demo' program should stop because the condition is resolved to false and therefore the cycle finishes.