O'Reilly logo

Visual Basic® .NET by Example by Bob Donald, Gabriel Oancea

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The Do Loop

There are certain cases in which you need to execute the body of the loop while a specific expression is True (or False). This means executing a loop an unknown number of times. You would not be able to use a counter and a range of values, as in a For loop. You can use a Do loop to solve this type of problem.

In the following example you would like to allow the user to perform a simple mathematical computation as many times as he or she wishes. To run the example, create a new console project and enter the code as shown.

Sub Main()
   Dim sContinue As String = "yes"

   Do While sContinue.Equals("yes") Console.Out.WriteLine("Enter the value for i and press <Enter>:") Dim i As Integer i = CInt(System.Console.In.ReadLine()) Console.Out.WriteLine("Enter ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required