Exit usage Summary

Source: Internet
Author: User

I just typed an example and wrote "Next" in the fornext loop structure as "exit". Later I thought about it and it actually had a similar meaning, so I found the use of exit so that I won't confuse it again next time.

Exit the do... loop, for... Next, function, sub, or property code block.

 

Syntax

 

Exit do exit for exit function exit property exit sub

 

Exit do provides a method to exit the do... loop and can only be used in the do... loop. Of course, if you do not use exit do, an endless loop will occur. Exit do transfers the control to the statement after the loop statement, that is, the loop stops. When exit do is used in a nested Do... loop, exit do transfers control to the outer loop where exit do is located.

 

Exit for provides a way to exit the for loop and can only be used in the for... next or foreach... next loop. Exit for transfers control to the statement after next. When exit for is used in a nested for loop, exit for transfers control to the outer loop where exit for is located.

 

The exit function immediately exits from the function that contains the statement. The program continues executing the statement after calling the function.

 

Exit sub immediately exits from the sub process that contains the statement. The program continues executing the sub statement after it calls the sub statement.

In general, the application of exit is different from that of end. end only represents the end of a process, while exit not only represents the end of a possible process, but also the start of another process. It is equivalent to a baton. End indicates that the competition is over, while exit indicates that one link is over, and the other link begins.

 

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.