• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
龙星之峰
抓住时间,改变现状
博客园    首页    新随笔    联系   管理    订阅  订阅

JavaScript学习与实践(11)

JS中的Break和Continue

      这是两个特殊的字段,用在循环之中,

例子:

用Break statement来跳出循环

 

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

 

他的执行结果在下面呢

 

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

Explanation: The loop will break when i=3.

 

 

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

posted @ 2007-01-21 23:31  lxsohu  阅读(166)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3