Skip to main content

Do while Loop

A do while loop is a control flow statement that allows code to be executed once based on a given boolean condition. In visual basic, you can use do while loop structure when you want to repeat a set of statements of an indefinite number of times, until a condition is satisfied.


Do  While condition
    [ statements ]
    [ Continue Do ]
    [ statements ]
    [ Exit Do ]
    [ statements ]

The Do while loop evaluate something that is true

  1. Dim num As Integer
  3. Do While num < 20
  4. num = num + 1
  5. MsgBox(num)
  6. Loop

Code Explanation:
1. Declare num variable as Integer
2. Then we use the Do While Loop to check if num is less than twenty
3. If less than twenty, it is true
4. Since it is true, we increment num by 1
5. Until it reaches 20 then, the statement will become false
6. Then we display the current value of num.

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.


1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment

This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.