View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default For Next Loop Question

An interesting fact I learned not too long ago:



Sub ABC()
For n = 1 To 10
For m = 1 To 10
For o = 1 To 10
For p = 1 To 10
Debug.Print n, m, o, p
Next p, o, m, n

End Sub

--
Regards,
Tom Ogilvy


" wrote:

It's probably good practice to write

for n=1 to 10
do something
next n

but it's exactly the same as

for n=10 to 10:do something:next

Reason for being good practice is

for n=1 to 10
for m = 1 to 10
for o=1 to 10
for p = 1 to 10
next
next
next
next

is harder to read!!! (and to debug - ESPECIALLY if the for next loops
are nested further apart than my example!