break和continue
程序员文章站
2022-06-16 10:26:31
...
continue:满足条件后会在递增之前退出循环,但接下来执行的是下一次训循环;
var num = 0;
for (var i = 1; i < 10; i++) {
if(i%5 == 0){
continue;
}
num++;
console.log(num); //12345678
}
alert(num) //8
break:满足条件后便立即退出循环;
var num = 0;
for (var i = 1; i < 10; i++) {
if(i%5 == 0){
break;
}
num++;
console.log(num); //1234
}
alert(num) //4