How to make For each stop looping after 10 rows?

I am executing some actions for each row of my data table, using a FOR EACH activity.

I want i limit the FOR EACH to a maximum of 10 Rows, so will stop looping after 10 times.

How to do this?

Using the For Each Row activity, there is a property in the properties panel called Counter. You can assign this to an Integer variable. Then inside your For Each Row activity, put an If activity to check whether your counter variable is less than 10. In the Else side of the condition, put a Break activity to break or if the loop. That would probably be the most straight forward way.

However, a more idiomatic way using .NET would be to use the take() LINQ method. So using a regular For Each activity (not For Each Row), use the expression:

MyDT.AsEnumerable().Take(10)

Make sure to change your Type argument to DataRow. And that will take only the first 10 inside the loop.

3 Likes

Hi @Biskat_Assistant

Use like this

  1. read the datatable using read range and store in datatable dt1

  2. assign a integer varible let’s say index = 1

  3. use for each row activitiy to loop.through each row of dt1

Inside the for each row , use the following operation

a) put an if condition with condition index >10
If it is true then in the then section put break activitiy so that it break after 10 rows

b) do nothing in else

C) after this increment the index by one

Hope it helps

Mark it as solution if u got it

Nived N :robot:

Happy Automation

4 Likes

@Biskat_Assistant

If index <10 then the condition is false then in else section u can make the sequence whatever u need

Hope it helps

Mark it as solution if you got it

Nived N :robot:

Happy Automation :relaxed: :relaxed:

1 Like

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