Whats the difference between these?
WPCode:(1)
While a > 1
...
Wend
(2)
Do While a > 1
...
Loop
Printable View
Whats the difference between these?
WPCode:(1)
While a > 1
...
Wend
(2)
Do While a > 1
...
Loop
None!
The Do loop can be written like this:
But using the first Do loop is the same as doing the While ... WEnd loop.Code:Do While a > 1
'...
Loop
'or like this
Do Until a > 1
'...
Loop
'or you can put the While|Until part at the end
Do
'...
Loop While a > 1
Do
'...
Loop Until a > 1
The reason for having two syntaxes that do the same thing is because the older While ... WEnd loop is an inheritance from older BASIC versions like QBasic.
The guy who wrote a VB Book I've got says that you should always use Do...Loop because it is more flexible.
;)
The Do..Loop iteration type gives you more possibilities to the wanted loop.
The While statement is yes indeed an inheritance of older BASIC versions.
Please note that pseudo-code also uses Do..Loop to explain an iteration process instead of the While notation, because of it's readibility.
Do...Loop is more flexible than Wend. For example, you can replace While with Until and you have the ability to exit the loop by using a simple Exit Do statement.
Thanks all of you a lot
WP