VBS Tutorial: VBscript-Exit statement

Source: Internet
Author: User

Exit statement

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

Exit Do

Exit For

Exit Function

Exit Property

Exit Sub

ExitThe statement syntax has the following forms:

Statement Description
Exit Do Provides an exit method.Do... LoopStatement method. OnlyDo... LoopStatement.Exit DoTransfer controlLoopStatement after the statement. In the nestedDo... LoopWhen used in a statement,Exit DoTransfers control to the previous nested loop where the loop is located.
Exit Provides an exit method.ForLoop Method. OnlyFor... NextOrFor Each... NextLoop.ExitTransfer controlNext. In the nestedForWhen used in a loop,ExitTransfers control to the previous nested loop where the loop is located.
Exit Function Exit immediatelyFunctionProcess. Continue callingFunction.
Exit Property FromPropertyExit during the process. Continue to execute the following callPropertyStatement of the process.
Exit Sub Exit immediatelySubProcess, continue to execute the callSub.

The following example illustrates how to useExitStatement:

Sub RandomLoop  Dim I, MyNum  Do                           ' Set an endless loop.    For I = 1 To 1000          ' Loop 1000 Times.      MyNum = Int(Rnd * 100)   'Generate a random number.      Select Case MyNum        'Returns the value of a random number.        Case 17: MsgBox "Case 17"          Exit For             ' If yes 17, Exit For...Next.        Case 29: MsgBox "Case 29"          Exit Do              ' If yes 29, Exit Do...Loop.        Case 54: MsgBox "Case 54"          Exit Sub             ' If yes 54, Exit Sub Process.        End Select    Next  LoopEnd Sub

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.