
You want to execute the statements in a block while a certain condition is true in your VB.NET program. With the While loop construct, you can do exactly this, but must be careful to avoid infinite loops.
This VB tutorial demonstrates the While loop. It provides syntax examples.
This is just about the simplest program that shows a While loop construct. An Integer i is used as the index variable. The While loop has one condition: i < 100. The two statements in the While loop's body will be executed repeatedly until that condition evaluates to false.
Program that uses While loop [VB.NET]
Module Module1
Sub Main()
Dim i As Integer = 0
While i < 100
Console.WriteLine(i)
i += 10
End While
End Sub
End Module
Output
0
10
20
30
40
50
60
70
80
90Multiple conditions. You can also use the And operator to put two conditions in the While loop. This will result in a more complex program, but sometimes multiple conditions are necessary.

The VB.NET language also provides the Do While loop construct. How is the Do While loop different from the While construct? The two loops function the exact same way, but have slightly different syntax. The Do While ends with the Loop statement. The While construct ends with the End While statement. Other than that, the constructs are precisely equivalent.
Do While LoopThe biggest worry when dealing with While loops in any programming language is an infinite loop. It is possible to use a termination condition that will never be reached. In the above program, if you remove the i += 10 statement, you will have an infinite loop. In a For loop, you are less likely to inadvertently remove the increment expression, making it a safer construct. The For Each loop is even safer.
For Loop Examples For Each Loop Examples
The While loop construct in the VB.NET language has a very clear syntactic form. The repetition of the While keyword in the End While statement makes it easier to quickly read and understand. Other than its syntactic form, it is equivalent to the Do While construct.
VB.NET Tutorials