break lable>>
loop: {
for (var i = 0; i < 5; i++) {
console.log('i= %d', i);
for (var j = 10; j < 13; j++) {
if (j == 11) {
break loop;
}
console.log('j= %d', j);
}
}
}
通過標籤引用,break 語句可用於跳出任何 JavaScript 代碼塊>>
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>");
}
continue label>>
var i, j;
loop1:
for (i = 0; i < 3; i++) { //The first for statement is labeled "loop1"
loop2: for (j = 0; j < 3; j++) { //The second for statement is labeled "loop2"
if (i === 1 && j === 1) {
continue loop1;
}
console.log("i = " + i + ", j = " + j);
}
}