"John Pass" <John
Pa**@discussions.microsoft.com> wrote in message
news:7B**********************************@microsof t.com...
:
: What is the difference between a While and Do While/Loop repetition
: structure. If they is no difference (as it seems) why do both exist?
The two constructs are very similar and often achieve the same results:
Dim i As Integer = 3
While i > 0
i = i - 1
Console.WriteLine("In the While loop")
End WHile
However, you have more flexibility with the Do/Loop structure. You can
use a Do While or a Do Until statement that may be clearer. The code is
essentially the same but one may be more appropriate than the other (it
is often a question of personal style more than anything else).
Do While i > 0
i = i - 1
Console.WriteLine("In the Do While loop")
Loop
Do Until i <= 0
i = i - 1
Console.WriteLine("In the Do Until loop")
Loop
However, the real benefit of a Do / Loop is that you can delay the
conditional until the Loop runs at least once. In the examples above, if
i was set to an initial value of 0, you'd never hit the
Console.WriteLine statement. In the following example however, you will
always process that line at least once:
Do
i = i - 1
Console.WriteLine("In the Do loop")
Loop Until i < 1
Ralf