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. Syntax:
Do  While condition
    [ statements ]
    [ Continue Do ]
    [ statements ]
    [ Exit Do ]
    [ statements ]
The Do while loop evaluate something that is true Example:
  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.

Add new comment