Promotic
WikipediaLinkedInYoutubeTwitterFacebook

Exit - statement of language VBScript

Description:
Exits a block of Do...Loop, For...Next or the whole function..
Syntax:

Exit Do

Exit For

Exit Function

 
Exit Do Provides a way to exit a Do...Loopstatement. It can be used only inside a Do...Loopstatement. Exit Do transfers control to the statement following the Loop statement. When used within nested Do...Loop statements, 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. When used within nested For...Next loops, 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.
Note:
For similar purpose in the JavaScript language is used the command break.
Example:
Dim i, MyNum
Do
  For i=1 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
© MICROSYS, spol. s r. o.Tavičská 845/21 703 00 Ostrava-Vítkovice