为什么“ 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>热门推荐
1 狗狗技能训练
5 如何训练狗狗笑
6 狗狗训练排便
9 狗狗响片训练
10 如何训练狗狗不捡食
11 狗狗尿训练
12 怎么训练狗狗找东西
13 狗狗训练站立
14 狗狗训练飞盘
15 鞍山狗狗训练
16 怎样训练泰迪狗狗谢谢
17 狗狗外出训练
18 怎么训练金毛狗狗大小便