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