Label Statement __javascript in JavaScript

Source: Internet
Author: User
In JavaScript, we may rarely use a label statement, but it is a good practice to apply a label statement, especially in a nested loop, where the continue and label can be accurately returned to the location of the program you want. Label statements, according to the book said the syntax is: label:statement: begin:for (var i = 0; i < i++) {A                    Lert (i); }
To give a more typical example, read the label after reading the application: (not added Label) var num = 0; for (var i = 0; i < i++) {for (var j = 0; J < + j) {if (i = 5 &&                   j = = 5) {break;              } num++; } alert (num); The loop jumps out of the J loop when I is 5,j 5, but continues the I loop, outputting 95
Compare the programs after using the label: (after adding the label)     var num = 0;     Outpoint:     for (var i = 0; i < i++) {         for (var j = 0 ; J < 10; J + +) {              if (i = = 5 && j = 5) {                    break outpoint;               {         num++;          }    }     alert (num); The loop jumps out of the double loop when I 5,j 5, returns to the Outpoint layer, continues, and outputs 55

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.