How to get an index for current iteration of For Each

Hi all,

I was wondering if there is a way to get the iteration number inside a for each activity (while it is running), other than using a counter.

To be more clear, is there something like a current index for the for each activity, that i can query and use? A quick example in the attached image:

Thank you,
Serban

@Serban

If your Collection is Distinct
Then Inside forEach
You can use
intCurrIndex= ListVariable.IndexOf(item)

Suppose if your Collection is not Distinct
Then Create one Counter Let us take intindex and initially assign 0
Then use
intCurrIndex=intindex
After that Increment it by one
intindex=intindex+1

Regards,
Mahesh

1 Like

Hi @Serban,

Try the below:

Array.IndexOf(arr,item).ToString

Regards,
Sasikumar K

5 Likes

Thank you very much!

If I need the index of an element in a ForEach I usually change my foreach to run over an array of indexes in the list and assign the element inside the loop.

image

1 Like

Hi @Serban

Since a while it is also possible to get the index of the current element by using new property in the Properties panel:
image

(when you update to the newest package versions)

12 Likes

right. didn’t see that :smile:
awesome, thank you!

1 Like

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