How to go from last to first item in the for each activity

I have dynamic number and i want to go through from last to first decreasing one by one.

For example ;

my number is 12 and ll go till 2.

12
11
10
.
.
.
.
2

How can i do it?

Hi @170290064

myList= New List(Of String)() {ā€œItem 1ā€, ā€œItem 2ā€, ā€œItem 3ā€}

myList=myList.Reverse()

For Each item In myList
log message

But the number is dynamic and it comes from somewhere as an integer which is like;

8 or 12 or 3

somethin like that

Hi @170290064

If you are storing these values in a array variable then reverse the array and iterate with the for each activity.

Try the below expression to reverse the array

Assign: myArray = myArray.Reverse().ToArray()

Then iterate the myArray in for each activity

Hope it helps!!

@170290064

if number comes 76 then how can i add it one by one ā€œvalue to saveā€ part like you showed ?

It has to be an easy way to add them in an array

if it is always a number you can use a do while and write do while (VarNumber - 1) > 0

we can create it dynamic
grafik

myStart = 2
myEnd = 12

Enumerable.Range(myStart ,myEnd -myStart + 1).Reverse().ToArray

Sometimes we should think easy :grinning:

Thanks my new junior robot friend :robot:

1 Like

Its okay! Hope it works please mark my response as the answer if it works :slight_smile:

I did already :ok_hand:

Happy automation :slightly_smiling_face:

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