Description
This activity is used for repetitive operations and follows the structure of the while loop in programming.
It differs in structure from the other activities. The "Do-while loop" activity itself is not a standard single activity block. By default, the "Do-while loop" consists of five connected blocks: "Assign value to variable", "If...then", two "TODO" blocks, and another "Assign value to variable" block. The arrangement of the blocks reproduces the structure of the cycle. The first "Assign value to variable" block allows you to set a variable-counter, which allows you to keep track of loop iterations. The next block - "If...then" - allows you to set the condition of the loop. The "TODO" blocks indicate the body of the loop (after the "Yes" branch) and the exit from the loop (after the "No" branch) and do nothing on their own. They are placed to show that you can specify a sequence of actions instead.
This is what the default action looks like:
Example
To make the activity ready to work, a little adjustment is needed. Let's see how this can be done, using a simple example - we'll output the iteration numbers to the console (let's say we want to iterate the loop 4 times).
Let's start with the variable-counter. Loops are integrally connected to iterations, which need to be counted somehow. In standard while loops, this is done with a variable-counter. In general, the counter and loop condition can be set in different ways. Among them, we can find situations where the counter initially takes a large value and then decreases. In our case, we'll set the counter to one because we just want to iterate through 4 loop actions and display the iteration number. Therefore, let's set up the first block "Set Variable Value" as follows (shown in the image below):
This is the variable-counter. It will be incremented with each iteration.
Next, set the loop condition. Since we want to iterate four times, the condition can look like counter <= 4 or counter < 5 (the counter variable is integer).
The condition to check. As soon as counter reaches 5, the loop will stop.
Now let's set how the counter will change. Since we make four consecutive iterations, the counter will increase by one. In other cases the counter change may be different.
In the last block, the counter variable is incremented with each iteration.
At this point, we already have an actually ready-to-go workflow. It only remains to replace the "TODO" blocks with activity blocks. Let's take the "Console log" activity and fill in the parameters as shown in the images below:
The message in the "Console log" parameter. In the beginning - the line with the message, then - the current counter value
An example of the message output to the console - the result of the work. The loop ended as soon as the condition was no longer satisfied.
Workflow with a "Do-while loop".