ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   what loop structure??? (https://www.excelbanter.com/excel-programming/394569-what-loop-structure.html)

paul[_17_]

what loop structure???
 
just a quick question what loop structure would be most appropriate to
use if im checking for a condition at the end of the loop? i dotn no
many other loops if anyone no,s ou there can they show me an example
so i can see how its done

thanks


George Nicholson

what loop structure???
 
Loops generally have 2 approaches. The following is from the VBA Help entry
on Do..Loop:

Do [{While | Until} condition]
[statements]
[Exit Do]
[statements]

Loop

Or, you can use this syntax:

Do
[statements]
[Exit Do]
[statements]

Loop [{While | Until} condition]

The primary difference between the 2 is that statements within the 1st
method will only be executed if the condition statement is initially True.

In the 2nd method, statements within the loop will always be executed at
least ONCE. After that, the condition has to be true for the loop to repeat.

So, its not really a question of what's best to test for a condition at the
end of the loop, either method will effectively do that. It's really a
question of what do you want to happen when the loop is first encountered.

HTH,


"paul" wrote in message
ups.com...
just a quick question what loop structure would be most appropriate to
use if im checking for a condition at the end of the loop? i dotn no
many other loops if anyone no,s ou there can they show me an example
so i can see how its done

thanks





All times are GMT +1. The time now is 05:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com