为什么“ continue”语句在JavaScript中不好?
“continue”语句的使用使代码难以理解。在大多数情况下,继续使用的使用意味着您的循环条件不足。为避免这种情况,可以将其添加到条件本身中,也可以在循环中使用。
但是,如果“continue”用法不一致或使用不当,那就不好了,否则它是一个有用的语句,并节省了大量内存和代码行。
示例
我们来看一个continue语句的例子
<html>
<body>
<script>
var x = 1;
document.write("Entering the loop<br /> ");
while (x < 10) {
x = x + 1;
if (x == 5) {
continue; // skip rest of the loop body
}
document.write( x + "<br />");
}
document.write("Exiting the loop!<br /> ");
</script>
</body>
</html>热门推荐
10 英语校庆祝福语简短
11 元旦快乐祝福语简短版
12 元旦聚会祝福语简短霸气
13 学生元旦快乐祝福语简短
14 外国老人的祝福语简短
15 恭贺新婚搞笑祝福语简短
16 结果祝福语大全简短赞美
17 元诞祝福语简短2026
18 男娃过生日简短祝福语