Exit Do
Exit For
Exit Function
Exit Do | Provides a way to exit a Do...Loop statement. It can be used only inside a Do...Loop statement. Exit Do transfers control to the statement following the Loop statement. If used within nested Do...Loop statements, then Exit Do transfers control to the loop that is one nested level above the loop where it occurs. |
---|---|
Exit For | Provides a way to exit a For loop. It can be used only in a For...Next or For Each...Next loop. Exit For transfers control to the statement following the For...Next statement. If used within nested For...Next loops, then Exit For transfers control to the loop that is one nested level above the loop where it occurs. |
Exit Function | Immediately exits the procedure in which it appears. |
Dim i, MyNum
Do
For i = 0 To 1000
MyNum = Int(Rnd() * 100)
Select Case MyNum
Case 17
MsgBox "Case 17"
Exit For
'exit For...Next statement
Case 29
MsgBox "Case 29"
Exit Do
'exit Do...Loop statement
End Select
Next
Loop While i < 100