当前位置: 首页 > 网络学院 > 客户端脚本教程 > JavaScript > JS Break 循环

JavaScript
JS数学对象参考
JS字符串对象参考
JS函数参考
JS事件参考
Javascript 常用正则表达式
FF和IE下的js兼容性问题
jQuery 简单介绍
jQuery / 核心 / $(expression, [context] ) 函数
jQuery / 核心 / $(html) 函数
如何使用JS来判断浏览器类型(ie、firefox,等等)
Javascript在IE和FireFox中的不同表现
3个js字符编码函数区别
javascript 中的 XMLDOM 对象

JavaScript 中的 JS Break 循环


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-01   浏览: 1083 ::
收藏到网摘: n/a

There are two special statements that can be used inside loops: break and continue.
break和continue是两个用在内部循环的特殊语句。


Examples
举例

Break statement
Use the break statement to break the loop.
使用break语句跳出循环

Continue statement
Use the continue statement to break the current loop and continue with the next value.
用continue语句来跳出当前的循环继续下面的值


JavaScript break and continue Statements
JS的break和continue语句

There are two special statements that can be used inside loops: break and continue.
break和continue是两个用在内部循环的特殊语句。(和第一句重复了-_-)

Break
跳出(也可以理解为离开)

The break command will break the loop and continue executing the code that follows after the loop (if any).
break命令会离开当前的循环并接着开始执行下面的循环(如果有的话)

Example
例子

<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>

Result
结果

The number is 0
The number is 1
The number is 2

Continue
继续

The continue command will break the current loop and continue with the next value.
continue命令会跳出当前的循环并继续下面的值

Example
例子

<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>

Result
结果

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

评论 (0) All

登陆 | 还没注册?