Label Statement break continue

Source: Internet
Author: User

Use the Label statement to add tags to your code for future use.

Statements with label labels are typically used in conjunction with loop statements such as for statements.

var num = 0;outermost:for (var i = 0; i <; i + +) {for    (var j = 0; J < J + +) {        if (i = = 5 && j = = 5) {break            outermost;        };        num++;      }  } alert (num);   55

(break) In the example above, the outermost tag represents an external for statement.

Cycle ideas:

When i = 0 o'clock, j = 0,1,2,3,4,5,6,7,8,9 A total of 10 times, that is to say:

0 10

1 10

2 10

3 10

4 10

5 5 (if judged, jump out of the outermost tag, that is, jump out of all for loops)

So a total cycle of 10+10+10+10+10+5=55 times;

Each num++, the final num = 55;

var num = 0;outermost:for (var i = 0; i <; i + +) {for    (var j = 0; J < J + +) {        if (i = = 5 && j = = 5) {            continue outermost;        };        num++;      }  } alert (num);  95

(continue) In the above example, the outermost tag represents an external for statement.

Cycle ideas:

When i = 0 o'clock, j = 0,1,2,3,4,5,6,7,8,9 A total of 10 times, that is to say:

0 10

1 10

2 10

3 10

4 10

5 5 (if judged, jump out of the outermost label of this cycle)

6 10

7 10

8 10

9 10

10<10, jump out of the loop;

So a total cycle of 10+10+10+10+10+5+10+10+10+10=95 times;

Each num++, the final num = 95;

Label Statement break continue

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.