Learn to program in Visual Basic .NET, the right way

Loops - Do Loop

What is a Do Loop?

A Do loop allows you to repeat an action under certain conditions.

Do While

A Do While loop will loop while a condition is True.

The condition can be checked either before or after the code inside of the loop executes.

The following demonstrates how to implement a Do While loop:

Fiddle: Live Demo

Do Until

A Do Until loop will loop until a condition is True.

The condition can be checked either before or after the code inside of the loop executes.

The following demonstrates how to implement a Do Until loop:

Fiddle: Live Demo

Remarks

Keep in mind that infinite loops are possible with Do loops. If you check for a condition that you know will always return a True value, then the Loop will execute until the application shuts down.