js打破循环_打破循环

js打破循环

js打破循环

The cert guide is maybe not 100% clear on the question of breaking out of a loop, but you can break and continue in all types of loops - for, while and foreach (the latter wasn't mentioned in the loops section of the book).

CERT的指导,也许是一个环路上的突破的问题不是100%清楚,但你可以break ,并continue在所有类型的循环- forwhileforeach (后者在书的环路部分没有提到)。

About the continue when in nested loops. Well, it is true that you can do < ?php for ($i = 0; $i < 10; $i++){ for ($j = 0; $j < 10; $j++){ if ($i % 2) { continue 2; } } // this line will be executed 5 times // and will write 0 2 4 6 8 echo $i; } ?> Or you can just continue or continue 1, rather than continue 2, like this < ?php for ($i = 0; $i < 10; $i++){ for ($j = 0; $j < 10; $j++){ if ($i % 2) { continue; } } // this line will be executed 10 times // and will write 0 1 2 3 4 5 6 7 8 9 echo $i; } ?>

关于嵌套循环中的continue。 好吧,的确可以做到<?php for($ i = 0; $ i <10; $ i ++){for($ j = 0; $ j <10; $ j ++){if($ i%2 ){继续2; }} //此行将执行5次// //写入0 2 4 6 8 echo $ i; }?>或者您可以continuecontinue 1 ,而不是continue 2 ,例如<?php for($ i = 0; $ i <10; $ i ++){for($ j = 0; $ j <10; $ j ++){如果($ i%2){继续; }} //此行将被执行10次//并将写入0 1 2 3 4 5 6 7 8 9 echo $ i; }?>

So yes, it is possible, but to me, these continue 2, continue 3 and so on can only cause confusion and make the code harder to follow. If I find myself in situation where I write continue 2, I would seriously think about restructuring this particular piece of logic.

所以是的,这是可能的,但是对我来说,这些continue 2continue 3等等只会造成混乱并使代码难以遵循。 如果我发现自己在写continue 2情况下,我会认真考虑重组这一特定逻辑。

Tell your friends about this post on Facebook and Twitter

FacebookTwitter上告诉您的朋友有关此帖子的信息

翻译自: https://www.phpied.com/breaking-out-of-the-loops/

js打破循环

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值