Home  >  Article  >  Backend Development  >  Use cases of continue in php

Use cases of continue in php

墨辰丷
墨辰丷Original
2018-05-15 15:58:343299browse

This article mainly introduces the use cases of continue in php. Interested friends can refer to it. I hope it will be helpful to everyone.

The key to using continue in PHP is to clearly distinguish the levels of the loop structure:

continue is used in the loop structure to skip the remaining code in this loop and evaluate the condition as When true, start executing the next loop. For example:

<?php  
    $i=0;  
    while($i<5)  
    {  
      if($i==2)  
       {  
         continue;  
       }  
      echo "$i<br>";  
      $i++;  
    }    
>

When $i is 2, it will jump out of the loop and execute the next loop. The output is:

0  
1  
3  
4

continue accepts an optional numeric parameter to determine how many loops to skip to the end of the loop. The default value is 1, which jumps to the end of the current loop.

 <?php  
for($m=0; $m <5; $m++)  
{   
     for($i=0; $i <5; $i++)  
     {  

        if($i > 3)  
        {  
          continue 2;          
       }  
       echo "$i    $m    <br>";  
     }  


 }  
?>

The result is

1 0   
2 0   
3 0   
0 1   
1 1   
2 1   
3 1   
0 2   
1 2   
2 2   
3 2   
0 3   
1 3   
2 3   
3 3   
0 4   
1 4   
2 4   
3 4

Related recommendations:

About how to use JavaScript Break and Continue statements

php flow control continue statement

javaScript break and continue statement

The above is the detailed content of Use cases of continue in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn