For Each Loop in 2023.4.1

Hi guys,

Using UiPath after a hot minute, and I’ve noticed that the For Each activity has changed from the standard ‘For each i in ___’ to this new one where it asks for a list of items and has this ‘Item’ argument (see attached).

I am not familiar with this version of the activity - I need to loop through a range from 1 to about 50 to repeat a certain click on a website. How can I achieve this on the new for loop? Thanks for any help in advance.

image

How about using the Repeat Number of Times activity instead?

image

1 Like

Hi @abhay-b

How about the following?
image

OrAlso:
image

Regards!

1 Like

Hi @abhay-b

If you storing the numbers in an Array, In assign activity take an variable lets say “ArrayNumbers”. Variable type will be Array(Int32) and use the below syntax.

ArrayNumbers=Enumerable.Range(1, 50).ToArray()

If you storing the numbers in an List, In assign activity take an variable lets say “ListNumbers”. Variable type will be List(Int32)(i.e “System.Collections.Generic.List(Int32)”) and use the below syntax.

ListNumbers=Enumerable.Range(1, 50).ToList()

You can use that either of one in For Each Loop or you can give “Enumerable.Range(1,50)” directly in for Each Loop. It will work.

Hope it helps!!

Regards,

1 Like

Hi all, thanks for your replies. I actually forgot to mention that I need the loop number (the incremented i) for the automation to work. How can I get this number to use as a variable?

@abhay-b ,
Hey ,
In the “For Each” Activity Properties Panel There is an Option to create “Index” .There you can create a variable .Lets Say Count.
The Initial Value of the Varibale Count will be 0.Then it will be auto incremented as your loop executes.
So you can use that Variable Count according to your requirement.

Regards,

1 Like

Thank you, this worked!

1 Like

The “currentItem” variable in the Repeat Number of Times activity gives you the index of the iteration. There’s no need to use an Enumerable.Range nor a separate Index variable to get the current iteration as you would in a For Each activity.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.