Visual Basic 2010 (Console) Guide
While Loops
While loops work the same way as the last of the Do examples.
Dim numEntered As Integer = 0
Dim total As Integer = 0
Console.Write("Enter a number or 999 to finish> ")
numEntered = Console.ReadLine()
While numEntered <> 999
total += numEntered
Console.Write("Enter a number or 999 to finish> ")
numEntered = Console.ReadLine()
End While
Console.WriteLine("The total of the numbers entered is {0}", total)
Console.ReadLine()
Having A Go
- Rewrite the program you wrote for the exercise on the previous page to use the while statement.