How to Use For Each Loop in UiPath: A Comprehensive Guide
In UiPath, the automation of day-to-day tasks is one of the main functions that allow processes to be more fluid and efficient. Looping is the traditional approach to automating the steps Implies such as running through collections or repeating actions. If one wants to perform multiple operations, e.g. iterating through rows in a DataTable, searching files in a directory, or elements in a list, using For Each and For loops in UiPath could be utterly great. In this blog we will show you how to use through both the For Each loop and For loop in UiPath
What is a Loop in UiPath?
A loop is a programming structure that repeats a block of code multiple times based on conditions In UiPath, loops are a crucial component for the implementation of processes that need to be repeated The two major types of loops that will often be your tasks along with UiPath are:
- For Each Loop
- For Loop
Let's explain how to use these.
How to Use For Each Loop in UiPath
The loop called For Each in UiPath is most generally used in cases where all elements of a collection or an array should benefit from execution. For instance, if you are dealing with a list or each row of a DataTable, you can use the For Each loop to easily reach and work with each item one at a time.

Steps to Use For Each in UiPath
- Move the screen to the left and right for each activity.
- In the process of your operation, access the Activities section and search for For Each.
- Move the For Each activity to the workflow.
- Specify the Collection
- Add a collection you want to go through in the For Each activity. This could be a list, an array, a DataTable, or some other enumerable collection type.
- If you want to work with a list of strings, for example, you should select the list variable at Values.
- Specify the item type.
- Moreover, you will have to mention what the kinds of things are that you are going through. In the case a list of strings is being iterated over the type name is String. In case of a list of integers, the type namely is Int32.
- Execute Operations Within the Loop
- Once the For Each loop has been initiated, further activities you place inside the loop will be done for each item of the collection. As provided by, you could use activities like Read File, Log Message, or Write Line within the loop to perform actions on each file.
Example of a For Each Loop in UiPath
Let us presume there is a stack of numbers, and the problem is to inject 10 into the already saved numbers. This is the way you can do it:
- Take the List(Of Int32) type variable (say numbersList).
- Initialize the list to be equal to some example values, such as {1, 2, 3, 4, 5}.
- Bring in the For Each activity and link it to numbersList for the collection.
- In the loop, use an assign activity to do what you have to do, namely to add 10 to each item, so that item = item + 10.
- As a further option, a Log Message activity could be used
In this case, the loop will be executed for five numbers i.e. each number from the list will be increased by 10 and the result will be logged.
How to Use For Loop in UiPath
The For loop in UiPath is handy when you need to do a particular action a certain number of times, such as looping through a range of numbers. Although this type of loop may not be as flexible as the For Each loop, it is easier to use if you know in advance the starting and ending points of the iteration.
Steps to Use For Loop in UiPath
- Drag and Drop the For Activity
- From the Activities pane, locate the For activity by dragging it into your workflow.
- Set the Loop Parameters
- In the For activity properties, these steps involve the specification of three parameters:
- Start: Loop counter variable's starting value (0, 1, or other).
- End: The value the loop counter must reach at the end.
- Step: The step size can be one but also any value between the two (1–any).
- Fill the Loop with Tasks
- Inside the loop, you can put all the actions you need to repeat. Every time the loop runs through, the counter (e.g., i) will be incremented by one step.
Example of a For Loop in UiPath

You can have a loop like this to count from 1 to 5 and then display each number if you want:
- Create a For activity with these parameters:</
- Start = 1
- End = 5
- Step = 1
- Inside the loop, a Log Message action is used to commit the current loop's counter value to log.
This loop will output the numbers one, two, three, four, and five in a row.
When to Use For Each vs For Loop in UiPath
- For Each Loop: The best use case of for each loop is to iterate over collections such as lists, arrays, or DataTables where you are not required to think about the index or the number of iterations. Always use this when you are working with data and you need to treat each element separately.
- For Loop: This loop is most suitable when you know in advance how many times you should iterate, for example, if you want to cycle through a series of numbers or execute a task a particular number of times. It's also very beneficial in situations where the tasks demand index-based operations.
Conclusion
Both the for each which is a sequential loop that goes through a collection and the for loop which is a sequential loop that repeats a specified number of times are the marble that are well-suited to good use in UiPath to pedal out redundant work and with your education to use them properly you will be able to make your projects run far more smoothly. The For Each loop is best suited for dealing with collections, while the For loop should be used for situations when specific counts of the items are needed to be processed.
You do have the required skill set to use these loops; therefore, you can now include them in your project work flow either for Functions related to data processing, file handling, or other tasks. Plus, you can also introduce the full potential of loops and, reduce the manual effort that comes with the loops based approach and Manage to make RPA (Robotic Process Automation) more dynamic and effective.
Have fun with autom
Lucille
An effort offers a chance to learn, and a result provides valuable lessons.
