VBS TUTORIAL: VBScript statement-exit statement _vbs

Source: Internet
Author: User

Exit statement

Quit do ... Loop, for ... Next, Function, or Sub code block.

Exit Do

Exit For

Exit Function

Exit Property

Exit Sub

The syntax for the Exit statement is in the following ways:

Statement Description
Exit do Provides an exit from do ... the method of the Loop statement. Only in Do ... used in the Loop statement. Exit Do transfers control to the statement after the Loop statement. In the nested do ... when used in the loop statement, theExit do transfers control to the upper-level nested loop where the loop is located.
Exit for Provides a way to exit the For loop. Only for ... Next or for each ... Next Loop. Exit for transfers control to the statement after Next . When used in a nested for loop,Exit for transfers control to the upper-level nested loop where the loop is located.
Exit Function Exit the Function procedure immediately from where it appears. Continue executing the statement following the statement that invokes the Function .
Exit Property Exit immediately from the property process in which it is located. Continue with the following statement that calls the property procedure.
Exit Sub Immediately exits the sub procedure from where it appears, and continues executing the statement following the statement that calls the sub .

The following example illustrates how to use the Exit statement:

  Sub randomloop Dim I, MyNum do '  sets the Dead loop.  for I = 1 to 1000 '  loop  1000  times.  MyNum = Int (Rnd *) '  produces random numbers.  Select case MyNum '  to find the value of a random number.  Case 17:msgbox "case"     exit  for '   if is , exit  for ... Next .  Case 29:msgbox "case"     exit  do '   if  , exit  do ... Loop .  Case 54:msgbox "case"     exit  Sub '   if it is  , exit the  Sub  procedure.  End Select   Next   Loop   End 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.