Iteration

For ... Next

Use a For Next loop when you know how many times you want to go round the loop before it starts .

 For N = 1 To 10
    Console.WriteLine("The number is {0}", N)
 Next

Do ... Loop

Use a Do loop when you don't know how many times will be going round the loop.

 Do
   Console.WriteLine("This will go on for ever")
 Loop

You can put the condition after the Do or after the Loop.

 Do
   Console.WriteLine("Enter a number less than 10")
   TheNumber = Console.ReadLine()
 Loop Until TheNumber <= 10

The condition can use either While or Until.

 Total = 0
 Do While Total < 20
   Console.WriteLine("Enter another number")
   TheNumber = Console.ReadLine()
   Total = Total + TheNumber
 Loop

While .. End While

This is important

That was important

You can do the same thing with a Do loop.

There is also a While loop but the Do loop can be used to do exactly the same thing.

 Total = 0
 While Total < 20
   Console.WriteLine("Enter another number")
   TheNumber = Console.ReadLine()
   Total = Total + TheNumber
 End While

< Selection | VisualBasic | String Functions >