如何使用break语句摆脱JavaScript循环?
break语句用于尽早退出循环,使之脱离封闭的花括号。
示例
您可以尝试运行以下代码,以了解如何使用break语句退出循环
<html>
<body>
<script>
var x = 1;
document.write("Entering the loop<br /> ");
while (x < 20) {
if (x == 5) {
break; // breaks out of loop completely
}
x = x + 1;
document.write( x + "<br />");
}
document.write("Exiting the loop!<br /> ");
</script>
</body>
</html>热门推荐
10 新年给妈妈简短祝福语
11 新年送老师简短祝福语
12 结婚婚庆祝福语简短
13 要过年了祝福语简短
14 女性生日祝福语简短优美
15 孙媳妇祝福语简短
16 新娘对伴娘祝福语简短
17 诗意新婚祝福语高级简短
18 新年恋人祝福语简短创意