How to Use Switch Case, Flow Switch, and Flow Decision in UiPath
In UiPath, automation of repetitive tasks is a major tool that ensures process streamlining and the project's overall effectiveness. One of the most frequent methods to automate tasks, such as those that require cycling through collections or repeating actions, is loops as in For Each and For Loops. In particular, the For Each and For loops in UiPath have a broad application scope, thereby giving a chance to carry out operations on multiple items. These include moving through rows in a DataTable, files in a folder, or elements in a list.
What is a Loop in UiPath?
A loop is a programming structure that is based on some specific conditions that allow a block of code to be executed multiple times. These code structures allow you to automate the production processes which use repetitive actions. There are two main types of loops that you'll work with in UiPath are:
- For Each Loop
- For Loop
Let's segregate the process of using both of them.
How to Use For Each Loop in UiPath
The For Each loop in UiPath is mostly used when you want to traverse every single item in a collection or array. For example, if you are working with a list of things or the content of different rows of a DataTable, the for-each loop can help you open and use each element one after another according to your needs.

Steps to Use For Each in UiPath
- Drag and drop the Repeat each action Activity
- You need to find the For Each option within the Activities section in your working space.
- Move the For Each activity into the workflow by dragging it there.
- Set the Collection
- In the For Each activity properties, you’ll need to specify the collection that you want to iterate over. To be more specific, a list, an array, a DataTable, or other enumerable collections are appropriate.
- For example, if you're working with a list of strings, you would select the list variable in the Values field.
- Define the Type of the Item
- It is very important that you also declare what type of the item you are iterating. The mystery of an amused list of strings will be called the ‘triplet.’ In computational logic, the numbers have an addressable position, which the Nodes are ‘hanging’ on.
- Operation of Insertions Inside the Loop
- As soon as the For Each loop is introduced, any activities placed inside the loop will be implemented for each item in the collection. For instance, if you possess a list of file names, you could implement tasks such as Reading File, Logging Message, or Writing Line within the loop to execute individuality.
Example of a For Each Loop in UiPath
Let's pretend you are dealing with a list of integer values and your aim is to add 10 to each value. Here is a step-by-step guide:
- Develop a conceptual List (Of Int32) variable (e.g., numbersList).
- The list should be initialized with some values such as {1,2,3,4,5}.
- Insert a For Each action and assign the collection to numbersList.
- Within the loop, by implementing a Buy activity, you can extend each element with a 10: item = item + 10.
- Optionally, through an activity Log Message show the new values.
In this example, the loop will be executed only five times the amount of numbers in the list, each one of them will be 10 plus their own value. The result will be stored in the log.
How to Use For Loop in UiPath
The UiPath For loop is applicable when you want to execute an operation for a certain number of times, for instance, specifying a series of numbers. The loop that you have selected here is not as flexible as the For Each loop because, from the beginning, you need to specify the start and end points of the iteration.
Steps to Use For Loop in UiPath
- For this activity, Drag and Drop
- In the Activities section, find the For activity by typing the name and drag it to the place in the flow where you want it.
- Define the Loop parameters
- In the For activity properties, you will be able to specify only three elements as the following:</
- Start: The loop counter, which usually is 0 or 1, is the initial value.
- End: The last value that the loop counter should get to.
- Step: Know how it increments between the iterations (for example 1, but also it could be any value).
- Add Activities Inside the Loop
- Within the loop, you are able to put the activities that you would like to repeat. On each turn of the loop, the counter (e.g., i) will be augmented by the step value.
Example of a For Loop in UiPath

In case you want to loop from 1 to 5 and then show each of the numbers, you might do the following:
- Insert a For activity with the parameters
- Start = 1
- End = 5
- Step = 1
- Inside the loop, add a Log Message activity to log the current value of the loop counter.
This loop will log the numbers 1, 2, 3, 4, and 5 in sequence.
When to Use For Each vs For Loop in UiPath
- For Each Loop: It is the most suitable for collections such as lists, arrays, or DataTables where there is no need for you to keep track of the index or number of iterations. Make use of it when you are dealing with data and you want each item to be processed individually.
- For Loop: The For loop is best when you know the exact number of iterations in advance, for example, when the task is executed for a definite range of numbers or a definite number of times. It is more convenient for the problems related to index-based operations.
Lucille
An effort offers a chance to learn, and a result provides valuable lessons.
