JavaScript tags mark JavaScript statements

JavaScript tags can mark JavaScript statements.
To mark JavaScript statements, add a colon before the statement:

label:
statements

The break and continue statements are just statements that can jump out of the code block.
grammar:

break labelname; 
continue labelname;

The continue statement (referenced with or without label) can only be used in a loop.
The break statement (quoted without a label) can only be used in a loop or switch.
By tag reference, the break statement can be used to jump out of any JavaScript code block:
Example:

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>"); 
}

Guess you like

Origin blog.csdn.net/Serena_tz/article/details/114086406