Exit Do (statement)


Exit Do


Causes execution to continue on the statement following the Loop clause.


This statement can only appear within a Do...Loop statement.


This example will load an array with directory entries unless there are more than ten entries-in which case, the Exit Do terminates the loop.

Const crlf = Chr$(13) + Chr$(10)

Sub Main()
  Dim a$(5)
    i% = i% + 1
    If i% = 1 Then
     a(i%) = Dir("*")
     a(i%) = Dir
    End If
    If i% >= 5 Then Exit Do
  Loop While (a(i%) <> "")

  If i% = 5 Then
    MsgBox i% & " directory entries processed!"
    MsgBox "Less than " & i% & " entries processed!"
  End If
End Sub

See Also

Stop (statement); Exit For (statement); Exit Function (statement); Exit Sub (statement); End (statement); Do...Loop (statement).

More information