Foreach index

Is there a way to get the index in the foreach loop? Also ability to increment or decrement the index as needed. Running into error conditions during the loop which require the loop to run again.

I was hoping for something like this in a regular for loop where you have access to the variable ‘i’.
for (int i = 0; i < fibarray.Length; i++)
{
System.Console.WriteLine(fibarray[i]);
}
System.Console.WriteLine();

Hi @sirwittles,

Yes, it’s possible. Please check it.

Main.xaml (6.5 KB)

3 Likes

Why not use the While-loop. You can create the i variable(count), new variable int i = 0.
While i < fibarray.Length
Writeline(fibarray(0))
i = i + 1

-Topi

1 Like

In UiPath, it’s also possible to use the Do While activity to achieve this matter:

Main.xaml (7.0 KB)

2 Likes

Works a treat. Thanks @acaciomelo!

1 Like