What is a For Each Row Loop?

You are currently viewing What is a For Each Row Loop?

The For Each Row loop works by iterating through a DataTable, row by row, and executing whatever actions are placed within the body of the loop. 

For example, you could use a For Each Row loop on a data table of new students to check whether they have enrolled in classes or not. 

The For Each Row activity can only be used with DataTable data types, discussed here. The For Each Row loop will not stop until all rows within the given DataTable have been processed.

What Does A For Each Row Loop Look Like?

For Each Row DataTable Diagram

How to use a For Each Row Loop in UiPath?

In UiPath, the For Each Row loop can be achieved using the For Each Row activity. The For Each Row activity can be used in both a sequence and a flowchart and works only with DataTables. Let’s take a look at the For Each Row Activity:

  • DataTable – Contains the DataTable you wish to loop through.
  • Row Name – This is a local variable name for the row you are currently processing. It is called a local variable as the scope is within the body of the loop only and the value is replaced every time a new row is selected from the DataTable. Even though the default name is “row”, this name can be changed to anything and is not shown in the Variables Panel.
  • Body – Contains the actions and activities you’re looking to repeat.

There are also additional properties that can be found in the properties panel:

  • Index – The zero-based index (i.e. starts at zero) of the current element in the collection. This can be useful for logging purposes for determining the progress of the loop.