Label 标签语句可以为一行语句添加标签,以便在复杂结构中,设置跳转目标
outerloop: //This is the label name for (var i=0; i < 5; i++) { console.log("Outerloop: " + i); innerloop: for (var j=0; j<5; j++) { if (j>3 ) break; //Quit the innermost loop if (i == 2) break innerloop; //Do the same thing if (i == 4) break outerloop; //Quit the outer loop console.log("Innerloop: " + j); } }
成功执行上述代码后,将显示以下输出。
Outerloop: 0 Innerloop: 0 Innerloop: 1 Innerloop: 2 Innerloop: 3 Outerloop: 1 Innerloop: 0 Innerloop: 1 Innerloop: 2 Innerloop: 3 Outerloop: 2 Outerloop: 3 Innerloop: 0 Innerloop: 1 Innerloop: 2 Innerloop: 3 Outerloop: 4
参考链接
https://www.learnfk.com/es6/es6-label-with-break.html
标签:outerloop,break,Outerloop,Innerloop,Quit,无涯,Label,Break,innerloop From: https://blog.51cto.com/u_14033984/9505260