break:跳出整个循环;
<html>
<body>
<script type="text/javascript">
var i=0
for (i=0;i<=10;i++)
{
if (i==3){break}
document.write("The number is " + i)
document.write("<br />")
}
</script>
</body>
</html>结果:
The number is 0
The number is 1
The number is 2continue:跳出当前循环,执行下一个循环;
<html>
<body>
<script type="text/javascript">
var i=0
for (i=0;i<=10;i++)
{
if (i==3){continue}
document.write("The number is " + i)
document.write("<br />")
}
</script>
</body>
</html>结果:
The number is 0
The number is 1
The number is 2
The number is 4
The number is 5
The number is 6
The number is 7
The number is 8
The number is 9
The number is 10
本文深入解析JavaScript中的循环控制语句,详细介绍了break和continue的作用及使用场景,通过示例代码展示了它们如何影响循环流程,旨在帮助开发者更熟练地掌握循环控制技巧。
890

被折叠的 条评论
为什么被折叠?



