Build a program containing a loop¶
What you will learn
- The loop flow functionality
- Use the
Do While
control 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 While
from Control Structures library to the builder canvas. -
Add a
Compare Integer
from Basic Function Blocks library inside the Loop. -
Add a
Wait
from Basic Function Blocks library inside the Loop and after the counter. -
Select
on theWait
function block and set waiting time to 0.5 seconds. -
Select
on theCompare Integer
function 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 theDo While
loop.



-
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.