The Do While activity enables you to execute a specified part of your automation while a condition is met. When the specified condition is no longer met, the project exits the loop.
This type of activity can be useful to step through all the elements of an array, or execute a particular activity multiple times. You can increment counters to browse through array indices or step through a list of items.
Do While activities are evaluated only after the body has been executed once.
To exemplify how to use a Do While activity, let’s create an automation that increments an integer variable from 0 to 10, and displays a message every time it is incremented.
- Create a new sequence.
- Create an integer variable,
Counter, with a default value of 0.
- Add a Do While activity to the Designer panel.
- In the Body section, add an Assign activity.
- Select the Assign activity, and in the Properties panel, in the To field, add the
- In the Value field, type
Counter+ 1. This helps you increment the value of the variable with one.
- Add a Write Line activity, under the Assign one.
- In the Text field, type "The counter is " +
Counter.ToString. This writes the value of the counter in the Output panel each time it is incremented.
- In the Condition section of the Do While activity, type
Counter< 10. The body of the Do While activity is repeated until the value of the
Countervariable is bigger than 10.
The project should look as in the following screenshot.
- Press F5. The automation is executed. Note that the Output panel displays the message indicated in the Write Line activity.
Updated 2 years ago
|About Control Flow|