Analysis on the usage of tag statements in JavaScript _ javascript tips-js tutorial

Source: Internet
Author: User
This article mainly introduces the usage of tag statements in JavaScript. The example analyzes the functions, definitions, and related usage skills of tag statements, you can refer to the examples in this article to analyze the usage of tag statements in JavaScript. Share it with you for your reference. The specific analysis is as follows:

Recently I am reading w3school, And then I see the js section,

《script》cars=["BMW","Volvo","Saab","Ford"];list:{document.write(cars[0] + "
"); document.write(cars[1] + "
"); document.write(cars[2] + "
"); break list;document.write(cars[3] + "
"); document.write(cars[4] + "
"); document.write(cars[5] + "
"); }《script》

See the list: It feels a little weird, and it says

JavaScript tag

As you can see in the switch statement chapter, you can mark JavaScript statements.

To mark a JavaScript statement, add a colon Before the statement:

The break and continue statements are only statements that can jump out of the code block.

Syntax:

break labelname; continue labelname;

The continue Statement (with or without tag reference) can only be used in a loop.
The break statement (without tag reference) can only be used in loops or switches.
Through tag reference, the break statement can be used to jump out of any JavaScript code block:

I didn't pay attention to it at the beginning. Then Baidu marked the javascript statement and read a blog. It was written in this way. Here we will learn from it:

For example:

parser: while(token != null) { //Code omitted here}

By adding a label to a statement, you can name the statement, so that it can be referenced anywhere in the program, and any statement can be marked,

However, the labeled statements are usually loop statements, that is, while, do/while, for, and for/in statements. Generally, you can use the break statement and continue statement to name the loop.

Exit an iteration of a loop or loop.

For example:

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.