JavaScript Break and Continue 语法及实例教程,下面我们来看看教程吧.
有两个特殊的报表,可用于内部循环:break loop。
范例
break语句
使用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>
<p>Explanation: The loop will break when i=3.</p>
</body>
</html>
Continue statement
继续使用声明,打破目前的循环,并继续在未来的价值。
<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>
<p>Explanation: The loop will break the current loop and continue with the next value when i=3.</p>
</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
Explanation: The loop will break the current loop and continue with the next value when i=3.
好了下面再看.
JavaScript的突破,并继续发言
有两个特殊的报表,可用于内部循环:打破并继续。
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 2