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.
Video Tutorial¶
Step-by-step Guide¶
-
Create a new program.
-
Add a
Loop Do Whilefrom Control Structures library to the builder canvas. -
Add a
Compare Integerfrom Basic Function Blocks library inside the Loop. -
Add a
Waitfrom Basic Function Blocks library inside the Loop and after the counter. -
Select on the
Waitfunction block and set waiting time to 0.5 seconds. -
Select on the
Compare Integerfunction block as shown in the picture.

-
Link operand 1 to the output of the loop cycle counter by pressing the link button and selecting the cycle count output of the
Do Whileloop.



-
Assign the other operand to 5 (this is the maximum number of runs).
-
Assign to the Condition operator a '<' sign.
-
the program
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.
