首页 > 其他 > 详细

break 和 continue

时间:2017-03-22 20:33:29      阅读:196      评论:0      收藏:0      [点我收藏+]
break 结束当前 for,foreach,while,do-while 或者 switch 结构的执行。从循环外代码执行;
break 可以接受一个可选的数字参数来决定跳出几重循环;
 
continue,跳出本次循环,从下次执行;
如:
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 0
The number is 1
The number is 2

--

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

 

 

break 和 continue

原文:http://www.cnblogs.com/Ph-one/p/6601749.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!