Usage analysis of label statements in JavaScript _javascript tips

Source: Internet
Author: User

This example analyzes the use of label statements in JavaScript. Share to everyone for your reference. The specific analysis is as follows:

Recently in looking at W3school, and then see the JS part,

<! DOCTYPE html>
 
 

See that list: It's a little weird, and it says,

JavaScript tags

As you can see in the chapter on the switch statement, JavaScript statements are tagged.

To mark a JavaScript statement, precede the statement with a colon:

Grammar:

Break LabelName; 

Continue labelname;

Continue statements (with or without a label reference) can only be used in loops.
The break statement (without a label reference) can only be used in loops or switch.
With a label reference, the break statement can be used to jump out of any JAVASCRIPT code block:

In the beginning has not noticed, then Baidu tagged javascript statements, read a blog, is this written, here for reference:

For example:

Parser: While
 (token!= null) {
 //code omitted here
}

By tagging a statement, you can give the statement a name so that it can be referenced anywhere in the program by using that name, and you can tag any statement,

But the tagged statements are usually those loop statements, that is, while, Do/while, for, and for/in statements, which are usually named loops, you can use the break statement and the continue statement to

Exit a loop or one iteration of the loop.

Such as:

<script type= "Text/javascript" > 
  outerloop: For 
   (var i = 0; i < i++) 
   { 
     innerloop: for  
     ( var j = 0; J < 10; J + +) 
      { 
        if (J > 3) 
        {break 
          ; 
        } 
        if (i = = 2) 
        {break 
          innerloop; 
        } 
        if (i = = 4) 
        {break 
          outerloop; 
        } 
        document.write ("i=" + i + "j=" + j + "<br>"); 
      } 
</script>

See this example I understand the list: I hope this article will help you with your JavaScript programming.

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.