Exit

Exit a block of Do...Loop, For...Next, Function, or Sub code.

Syntax
      Exit Do
      Exit For
      Exit Function
      Exit Property
      Exit Sub

Exit will immediately exit the procedure or loop in which it appears. Execution will continue with the next statement/command.

Exit Do can be used only inside a Do...Loop statement.

When used within nested loops, Exit will only exit the current loop.

Examples

Dim indexA, indexB

For indexA = 1 to 2
    For indexB = 5 to 50
        If indexB > 9 Then
            Exit For
        End If
        document.write (indexA & "~" & indexB)
    Next
Next

' Output: 1~5 1~6 1~7 1~8 1~9 2~5 2~6 2~7 2~8 2~9

“Affairs are easier of entrance than of exit; and it is but common prudence to see our way out before we venture in” ~ Aesop

Related VBScript commands

Do..Loop - Repeat a block of statements.
Wscript.Quit - Exit a VBScript script.


 
Copyright © 1999-2024 SS64.com
Some rights reserved