UiPath Studio

The UiPath Studio Guide

The While Activity

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.

Example of Using a While Activity

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.

  1. Create a new sequence.
  2. Create an integer variable, Counter, with the default value of 10.
  3. Add a While activity to Designer panel.
  4. 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 Counter variable is going to be bigger than 100.
  5. In the Body section of the While activity, add an Assign activity.
  6. In the Properties panel, in the To field add the Counter.
  7. In the Value field, type Counter + 1. This increments the value of the Counter with one.
  8. 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.

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

  1. In the Text field, type "The counter is now " + Counter.ToString +".".
    The final project should look as in the following screenshot.
  1. Press F5. The automation is executed.
  2. Double-click the Word document specified at step 9. Note that all the numbers between 10 and 100 are written, as expected.

Download example

Updated 3 years ago

The While Activity

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.