What's the difference between Do While where the statement is the first line in the loop block and just the single While in VB.NET?
They don't seem to offer any difference in behavior.
The do-while loop is very similar to that of the while loop. But the only difference is that this loop checks for the conditions available after we check a statement. Thus, it is an example of a type of Exit Control Loop.
In a nutshell, the structure of a while loop is very similar to that of a do-while loop, but the main difference lies in the fact that the while loop evaluates the condition first before executing the statements whereas the do-while loop executes the statements first before evaluating the condition of the loop.
While loop because Python does not have do while loop. It depends on what you want to use it for. A while loop won't run if the condition is false, but a do-while loop will run at least once before it is terminated.
In Visual Basic these are identical:
Dim foo As Boolean = True
While Not foo
Debug.WriteLine("!")
End While
Do While Not foo
Debug.WriteLine("*")
Loop
These are not; the do
executes once:
Dim foo As Boolean = True
While Not foo
Debug.WriteLine("!")
End While
Do
Debug.WriteLine("*")
Loop While Not foo
In DO...WHILE, the code inside the loop is executed at least once
In WHILE Loop, the code inside the loop is executed 0 or more times.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With