Do...Loop (statement)

Syntax 1 Do {While | Until} condition statements Loop
Syntax 2 Do  statements Loop {While | Until} condition
Syntax 3 Do  statements Loop
Description Repeats a block of Basic Control Engine statements while a condition is True or until a condition is True .
Comments If the {While | Until} conditional clause is not specified, then the loop repeats the statements forever (or until the script encounters an Exit Do statement). The condition parameter specifies any Boolean expression.
Examples
Sub Main()
  'This first example uses the Do...While statement, which performs
  'the iteration, then checks the condition, and repeats if the
   'condition is True.
 
  Dim a$(100)
  i% = -1
  Do
    i% = i% + 1
    If i% = 0 Then
      a(i%) = Dir("*")
    Else
      a(i%) = Dir
    End If
  Loop While(a(i%) <> "" And i% <= 99)
  r% = SelectBox(i% & " files found",,a)
End Sub 
Sub Main()
  'This second example uses the Do While...Loop, which checks the
  'condition and then repeats if the condition is True.
 
  Dim a$(100)
  i% = 0
  a(i%) = Dir("*")
  Do While (a(i%) <> "") And (i% <= 99)
    i% = i% + 1
    a(i%) = Dir
  Loop
  r% = SelectBox(i% & " files found",,a)
End Sub
Sub Main()
  'This third example uses the Do Until...Loop, which does the
  'iteration and then checks the condition and repeats if the
  'condition is True.
 
  Dim a$(100)
  i% = 0
  a(i%) = Dir("*")
  Do Until (a(i%) = "") Or (i% = 100)
    i% = i% + 1
    a(i%) = Dir
  Loop
  r% = SelectBox(i% & " files found",,a)
End Sub
Sub Main()
  'This last example uses the Do...Until Loop, which performs the
  'iteration first, checks the condition, and repeats if the
  'condition is True.
 
  Dim a$(100)
  i% = -1
  Do
    i% = i% + 1
    If i% = 0 Then
      a(i%) = Dir("*")
    Else
      a(i%) = Dir
    End If
  Loop Until (a(i%) = "") Or (i% = 100)
  r% = SelectBox(i% & " files found",,a) 
End Sub
See Also For...Next (statement); While ...WEnd (statement).
Notes: 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.