Do…Loop Structure

Do…loop is used to execute a block of statements for indefinite number of times. There are several variations of Do…Loop statement.
Each variation evaluates a numeric condition to determine whether to continue execution or not.

Syntax:

Do While <condition>
statements…
Loop

Note that:

1.When Visual Basic executes Do While loop, it first tests condition.

2.If condition is False (zero), it skips past all the statements.

3.If it’s True (nonzero), Visual Basic executes the statements and then goes back to the Do While statement and tests the condition again.

Example:

Do While count<=5
count = count + 1
Loop

Here loop increments the value of count until it becomes equal or less than 5.
Another variation of Do…Loop statement executes the statement first and then tests condition after each execution. This variation guarantees at least one execution of statements.

Syntax:

Do
<statement>
Loop While <condition>