The While Loop

The While loop is a less used variation of the Do loop, and was maintained in the language mostly for historical reasons (in our opinion). It is totally superseded in functionality by the Do loop. We will present it for completeness, but recommend that you do not use it.

The formal syntax is

						While <conditional-expression>
   <statements>
End While
					

The last example could be re-written using a While loop as shown:

Dim i As Integer =
						1, t As Integer
While i <= 31
   t += i
   i
						+= 1
						End While
Console.Out.WriteLine("The final value of t is {0} ", t)

As you can see it is virtually identical to the Do loop, except for the lack of the Do keyword and the use of End While as loop terminator.

Another important thing to remember is that the

Get Visual Basic® .NET by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.