Hello everyone
Sometimes we have to use nested loops, in that case what is the best and faster? To loop large loops first then inside small loops or the vice-versa
To be more cleared, suppose we have 500 rows and we need with each row to loop through 15 columns, so we use this structure
For i = 1 To 500
for ii=1 To 15
Or to use the structure
For ii=1 To 15
For i = 1 To 500
Or both the approaches are the same and no difference.
Large loops inside small loops or vice-versa
-
- PlatinumLounger
- Posts: 4930
- Joined: 31 Aug 2016, 09:02
-
- Administrator
- Posts: 78524
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Large loops inside small loops or vice-versa
It shouldn't make any difference: in both cases, the inner statements are executed 15 * 500 = 7500 times
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4930
- Joined: 31 Aug 2016, 09:02
Re: Large loops inside small loops or vice-versa
Thanks a lot my tutor.