╋艺 镇╋╋网站网络|程序语言|Flash╋┣◇网站建设&Web语言 → JS Break和Continue循环


  共有14980人关注过本帖树形打印复制链接

主题:JS Break和Continue循环

美女呀,离线,留言给我吧!
admin
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 司令 亲民勋章
等级:管理员 帖子:3027 积分:27515 威望:0 精华:7 注册:2003/12/30 16:34:32
JS Break和Continue循环  发帖心情 Post By:2012/1/19 10:05:14 [只看该作者]

break和continue是两个用在内部循环的特殊语句。

使用break语句跳出循环
用continue语句来跳出当前的循环继续下面的值



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

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

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





http://www.1netmedia.cn/base/blogview.asp?logID=831


  
“艺镇”官方站:www.zyzsky.com QQ群:1221854  回到顶部