The While activity enables you to execute a specific process repeatedly, while a specific condition is met. The main difference between this and the Do While activity is that, in the first one, the condition is evaluated before the body of the loop is executed.
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.
To exemplify how to use a While activity, let’s create an automation that increments an integer variable from 10 to 100, and writes all the numbers to a Microsoft Word document.
- Create a new sequence.
- Create an integer variable,
Counter, with the default value of 10.
- Add a While activity to Designer panel.
- In the Condition field, type
Counter< 100. This means that the body of the loop is going to be repeated until the value of the
Countervariable is going to be bigger than 100.
- In the Body section of the While activity, add an Assign activity.
- In the Properties panel, in the To field add the
- In the Value field, type
Counter+ 1. This increments the value of the
- Add an Append Text activity under the Assign one.
This activity is part of the Word activities package. If you do not have it, use the package manager functionality to install it.
- In the FilePath field, type the path of a Word document in between quotation marks.
Make sure that the Word document is not used when running the automation, otherwise a message error is displayed and the execution is stopped.
- In the Text field, type "The counter is now " +
The final project should look as in the following screenshot.
- Press F5. The automation is executed.
- Double-click the Word document specified at step 9. Note that all the numbers between 10 and 100 are written, as expected.
Updated 3 years ago
|About Control Flow