break和continue的区别

来源:互联网 发布:儿童 编程 编辑:程序博客网 时间:2024/04/28 22:48

break:跳出整个循环;

<html><body><script type="text/javascript">var i=0for (i=0;i<=10;i++){if (i==3){break}document.write("The number is " + i)document.write("<br />")}</script></body></html>

结果:

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


continue:跳出当前循环,执行下一个循环;

<html><body><script type="text/javascript">var i=0for (i=0;i<=10;i++){if (i==3){continue}document.write("The number is " + i)document.write("<br />")}</script></body></html>
结果:

The number is 0The number is 1The number is 2The number is 4The number is 5The number is 6The number is 7The number is 8The number is 9The number is 10



原创粉丝点击