Home  >  Article  >  Backend Development  >  Use case sharing of continue in php

Use case sharing of continue in php

黄舟
黄舟Original
2017-06-25 09:42:091221browse

continue In the loop structure is used to skip the remaining code in this loop and start executing the next loop when the condition evaluates to true . 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

0 0 
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

The above is the detailed content of Use case sharing 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