While...Wend (statement)

Syntax While condition   [statements] Wend
Description Repeats a statement or group of statements while a condition is True .
Comments The condition is initially and then checked at the top of each iteration through the loop.
Example This example executes a While loop until the random number generator returns a value of 1.
Sub Main()
  x% = 0
  count% = 0
  While x% <> 1 And count% < 500
    x% = Rnd(1)
    If count% > 1000 Then
      Exit Sub
    Else
      count% = count% + 1
    End If
  Wend
  MsgBox "The loop executed " & count% & " times."
End Sub
See Also Do...Loop (statement); For...Next (statement).
Note: Due to errors in program logic, you can inadvertently create infinite loops in your code. You can break out of infinite loops using Ctrl+Break.