為什麼“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