You are here

Do Loops vb.net turoail

Do

The Do Loop is called the Do Loop because it "does commands" under certain conditions. There are two types of the Do Loop.

Do While

The Do While Loop does commands while a certain condition holds. See the code below for an example of the Do While Loop


Do while x < 100
x = x + 1
Loop
Msgbox (x)

You can also put the While condition after the Loop command. See the code below for an example.


Do
x = x + 1
Loop While x < 100
Msgbox (x)

If the while is put at the Do line then it will check the condition before it executes the commands. If the while is put at the Loop line then it will execute the commands first before checking the condition. The program will loop based on the conditions given.

The Do While Loop takes on the basic structures below.


Do While [condition}
[command lines]
Loop

OR


Do
[command lines]
Loop While [condition]

Do Until

The Do Until Loop is called a Do Until Loop because it runs commands until a certain condition is satisfied. Check out the code below for an example.


Do until x = 7
x = x + 1
Loop
Msgbox (x)

Like the Do While Loop, you can also put the until command on the Loop line just like the code below.


Do
x = x + 2
Loop Until x = 12
Msgbox (x)

If the Until is put on the Do line then the computer will check the condition before it performs the commands while if the Until is put on the Loop line then the computer will execute the commands first before checking the conditions.

The Do Until Loop takes on the structures below.


Do Until [condition]
[command lines]
Loop

OR


Do
[command lines]

Source :- http://www.edumax.com/
Loop Until [condition]

Forums: