Flag-controlled loop

Keywords: 
Situation: 

You want to a program to keep doing something until (or while) something happens.

Actions: 

Use a flag to remember whether something happened. Use a Do-Loop to test the flag.

Explanation: 

Flowchart

Example: loop until user enters valid data.

  1. Dim errorFlag As Boolean
  2. errorFlag = False
  3. Do
  4.     userInput = InputBox(prompt)
  5.     If [test] Then
  6.         errorFlag = True
  7.     ElseIf [test] Then
  8.         errorFlag = True
  9.     ElseIf [test] Then
  10.         errorFlag = True
  11.     End If
  12.     If errorFlag Then
  13.         [Show error message]
  14.     End If
  15. Loop While errorFlag