码迷,mamicode.com
首页 > 其他好文 > 详细

break 和 continue

时间:2017-03-22 20:33:29      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:代码   pre   switch   blog   write   数字   var   span   bsp   

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

标签:代码   pre   switch   blog   write   数字   var   span   bsp   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!