Home > Backend Development > PHP Tutorial > Use case sharing of continue in php

Use case sharing of continue in php

黄舟
Release: 2023-03-11 11:12:02
Original
1294 people have browsed it

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++;
     }  
?>
Copy after login


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

0
1
3
4
Copy after login

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>";
     }
     
     
 }
?>
Copy after login

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template