讲continue的地方
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;
} else {
console.log("i = " + i + ", j = " + j);
}
}
}
// Output is:
// "i = 0, j = 0"
// "i = 0, j = 1"
// "i = 0, j = 2"
// "i = 1, j = 0"
// "i = 2, j = 0"
// "i = 2, j = 1"
// "i = 2, j = 2"
// Notice how it skips both "i = 1, j = 1" and "i = 1, j = 2"
请问为什么"i = 1, j = 1" and "i = 1, j = 2"都被掠过了,不明白第二个为什么会被跳掉
mozilla
javascript
实例
------解决方案--------------------
continue loop1;
这个意思就是 从这里开始马上继续执行loop1。也就是说跳出loop2 这里类同 break;跳出当前循环继续执行 。当然这个 continue loop1; 更加灵活
------解决方案--------------------
loop1:
for (i = 0; i < 3; i++)
continue loop1;//继续 loop1的循环