This article analyzes the usage of tag statements in JavaScript. Share it for your reference. The specific analysis is as follows:
I've been looking at w3school recently, and then I've seen the js part.
<!DOCTYPE html><html><body><script>cars=["BMW","Volvo","Saab","Ford"]; list:{document.write(cars[0] + "<br>"); document.write(cars[1] + "<br>"); document.write(cars[2] + "<br>"); break list;document.write(cars[3] + "<br>"); document.write(cars[4] + "<br>"); document.write(cars[5] + "<br>"); }</script></body></html>Seeing that list: It feels a little weird, and it says
JavaScript Tags
As you can see in that chapter of switch statements, JavaScript statements can be marked.
To mark a JavaScript statement, add a colon before the statement:
label:statements
The break and continue statements are just statements that can break out of the code block.
grammar:
break labelname; continue labelname;
The continue statement (with or without tag references) can only be used in loops.
The break statement (without tag references) can only be used in loops or switches.
Through tag references, break statements can be used to break out of any JavaScript code block:
I didn't pay attention to it at the beginning, and then I marked the JavaScript statement on Baidu and read a blog. It was written like this. Let me learn from it here:
For example:
parser: while(token != null) { //Code omitted here}By tagging a statement, you can give the statement a name, so that this name can be used anywhere in the program to reference it, and any statement can be marked.
However, the marked statements are usually those loop statements, namely while, do/while, for and for/in statements. Usually, the loop is named, and you can use break statements and continue statements to
Exit the loop or a certain iteration of the loop.
like:
<script type="text/javascript"> outerloop: for (var i = 0; i < 10; 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>After seeing this example, I understand and understand the list: I hope that the description in this article will be helpful to everyone's javascript programming.