Usage of PHP function continue in Loop Structure

Source: Internet
Author: User

In actualThe difference between the PHP function continue is that it accepts an optional numeric parameter to decide to skip several repeated loops to the end of the loop.

In php, continue is used in the loop structure to skip the remaining code in this loop and start executing the next loop. This is the same as that in other languages. However, the other trick is that continue accepts an optional numeric parameter to decide to skip several iterations to the end of the loop.

 
  1. #php_continue.php  
  2.  
  3. $i = 0;  
  4. $j = 0;  
  5. while ($i++ <3) {//level 3  
  6. echo "Outer  
  7. n";  
  8. while (1){//level 2  
  9. echo "Middle  
  10. n";  
  11. while (1){//level 1  
  12. echo "Inner  
  13. n";  
  14. continue 3;  
  15. }  
  16. echo "Thisnever gets output.  
  17. n";  
  18. }  
  19. echo"Neither does this.  
  20. n";  
  21. $j++;  
  22. //after runscontinue 3,it comes to the end of level 3  
  23. }  
  24. echo"$j=$j";//output: $j=0 
  25. ?> 

The above code is the specific usage of the PHP function continue. I hope it will be helpful to you.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.