Exit Do (statement)

Syntax

Exit Do

Description

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

Comments

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

Example

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)
  Do
    i% = i% + 1
    If i% = 1 Then
     a(i%) = Dir("*")
    Else
     a(i%) = Dir
    End If
    If i% >= 5 Then Exit Do
  Loop While (a(i%) <> "")

  If i% = 5 Then
    MsgBox i% & " directory entries processed!"
  Else
    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

E