How to loop through specific number of rows

Take a look at this solution.