公告:本站提供编程开发方面的技术交流与分享,打造最佳教程网,希望能为您排忧解难!

JS教程Javascript基础:break和continue语句

Javascript基础:break和continue语句

更新时间:2013-05-27 21:05:54 |

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> </body> </html>

结果:

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

Continue

continue语句会终止本次的循环(后面的语句)的执行,然后继续运行下一次循环。

实例:

<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

 

最佳教程网

最大的技术交流平台 www.goodxyx.com© CopyRight 2011-2013, All Rights Reserved

浙ICP备11033019号