Executes a series of statements as long as a given condition is True.
While condition [ statements ] End While
If condition is True, all of the statements are executed until the End While statement is encountered. Control then returns to the While statement and condition is again checked. If condition is still True, the process is repeated. If it is False, execution resumes with the statement following the End While statement.
You can nest While loops by placing one loop within another.
This example uses the While...End While statement to increment a counter variable. The statements in the loop are executed as long as the condition evaluates to True.
Dim Counter As Integer = 0While
Counter < 20 ' Test value of Counter. Counter += 1 ' Increment Counter.End While
' End While loop when Counter > 19. Debug.WriteLine (Counter) ' Prints 20 in the Output window.
Do...Loop Statements |