Special usage and introduction of break and continue in javascript

Source: Internet
Author: User

Today, when studying a system, we found that its code has such a structure (simplified ):
Copy codeThe Code is as follows:
Var result = false;
Var obj = {key: 1 };
For (var key in obj ){
Break point;
Result = true;
Alert (result );

I thought it was a code error, and even Visual Studio could not properly format the code. However, a closer look at the semantics is clear, that is, from the break inside the for loop to the specified point, and the system should not make such a mistake. Because I have never used it like this, I did some tests. The test results are really academic... This is a javascript syntax. break can contain location tags. You can refer to relevant documents and find that continue can also contain location tags.

Their syntax is:

Break [label];
Continue [label];
We know that in the loop body, the break can only jump out of the current loop. When the break is tagged, it can jump to a certain position and easily jump out of multiple loops, in addition, the break in the switch can also be used in this way.



Related Article

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.