What is a Do While Loop?

You are currently viewing What is a Do While Loop?

A do while loop is one of the most common types of loop. The Do While loop works by repeating a given set of actions while a specified condition is true. A Do While loop checks if the condition is true AFTER processing the body of the loop. This type of loop is very useful when we don’t know the exact number of times a section of code needs to be executed.  

Do While loops contain two major components, a Condition and a Body:

  • Condition – Contains a conditional statement that when true, will continue repeating, but when set to false, will exit the loop. Must be a Boolean data type.
  • Body – Contains the actions and activities you’re looking to repeat.

Keep in mind that you need a way to set the condition to false in order to stop the do while loop, otherwise, the loop will execute the code infinitely.

What Does a Do While Loop Look Like?

How to use a Do While Loop in UiPath?

In UiPath, the Do While loop can be achieved by using the Do While activity. The Do While activity can be used in both a sequence and a flowchart. Let’s take a look at the Do While Activity:

As discussed above, there are only two components required, a condition and a body. Note that the body is above the condition as that is the order in which the actions will be performed. The actions inside the body will be performed prior to any condition examined.