1. Computing

Chapter 7 - Using Loops and Timers - Part 1

By

3 of 8

Loop Conditions - How to control when the loop stops

The condition that controls whether the statements inside the loop are executed again can be:

  • While
  • Until
  • To (in: For counter = start To end)

Virtually any program statements can be inside the loop (including more looping statements). As a bonus, we'll get a jump on the next chapter (which covers program debugging) by showing you a debugging statement that the book doesn't cover, Debug.WriteLine , that will help you understand what the loop does.

The While and Until conditions that controls whether the statements inside the loop are executed again can be found either at the beginning of the loop or at the end. In other words, you can code:

~~~~~~~~~~~~~~~~~~~~~~~~~
Do While condition
...
Loop
~~~~~~~~~~~~~~~~~~~~~~~~~

or

~~~~~~~~~~~~~~~~~~~~~~~~~
Do
...
Loop While condition
~~~~~~~~~~~~~~~~~~~~~~~~~

But you can't have the condition at both the beginning andat the end.

  1. About.com
  2. Computing
  3. Visual Basic
  4. Learn VB.NET
  5. Using Loops and Timers - Part 1

©2014 About.com. All rights reserved.