Exits a block of Do...Loop, For...Next, Function, or Sub code.
Syntax for VBScript Exit Statement
Exit Do
Exit For
Exit Function
Exit Sub
The above Exit statements used for exit from respective block of the statement.
Sub RandomLoop
Dim I, MyNum
Do ' Set up infinite loop.
For I = 1 To 1000 ' Loop 1000 times.
MyNum = Int(Rnd * 100) ' Generate random numbers.
Select Case MyNum ' Evaluate random number.
Case 17: MsgBox "Case 17"
Exit For ' If 17, exit For...Next.
Case 29: MsgBox "Case 29"
Exit Do ' If 29, exit Do...Loop.
Case 54: MsgBox "Case 54"
Exit Sub ' If 54, exit Sub procedure.
End Select
Next
Loop
End Sub
No comments:
Post a Comment