在javascript中使用标签

Elm*_*mor 1 javascript

你能解释一下如何在与break:switch,while,do和for交互的语句中使用标签.

请举例说明.

Jos*_*eph 9

通常,我看到它突破外部循环:

var i, j;

dance: for (i = 0; i < 20; i++) {
    for (j = 0; j < 20; j++) {
        console.log(i+'-'+j);
        if (j === 10) { //normally, break only breaks the immediate loop
            break dance; //this one breaks the loop labelled as dance
        }
    }
}?

//continue here after i = 0,j = 10
Run Code Online (Sandbox Code Playgroud)