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: