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打破循环

相关文章:

  • 2022-12-23
  • 2021-09-01
  • 2022-03-01
  • 2021-05-06
  • 2021-09-26
  • 2021-12-14
猜你喜欢
  • 2021-09-01
  • 2021-05-15
  • 2021-05-27
  • 2021-10-06
  • 2021-04-11
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案