为什么“continue”语句在 JavaScript 中是糟糕的?
使用“continue”语句会使代码难以理解。在大多数情况下,使用 continue 意味着你的循环中的条件不足。为了避免这种情况,你可以将它添加到条件中或在循环中使用 if。
但是,“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>
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP