Skip to content

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

  1. Create a new program.

  2. Add a Loop Do While from Control Structures library to the builder canvas.

  3. Add a Compare Integer from Basic Function Blocks library inside the Loop.

  4. Add a Wait from Basic Function Blocks library inside the Loop and after the counter.

  5. Select Set Parameter on the Wait function block and set waiting time to 0.5 seconds.

  6. Select Set Parameter on the Compare Integer function block as shown in the picture.

    ![Set parameter of the loop](images/loop_with_counter/b_1.png)

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

    ![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)

  1. Assign the other operand to 5 (this is the maximum number of runs).

  2. Assign to the Condition operator a '<' sign.

  3. Save & Run 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.