PHP break   continue statements

the break ends execution of the current for, foreach, while, do-while or switch structure.

the continue statement 'jumps over' one iteration in the loop.


PHP break statement

the break ends execution of the current for, foreach, while, do-while or switch structure.

syntax:

         break [ label ] ;
   <?php
         
     function    infinite(){
                     
               while( true )
                               {
               
                                echo("it's infinite loop you can break this");
               
                                 break;
                         }    
               }   
   ?>  

the following function has a break statement that terminates the for loop when i is 4, and returns the value 4*i.

 function   testbreak($x){
     
                  for ( $i = 0; $i < 6 ; $i++ ){
                  
                                           if ( $i == 4 ) break;
                                           
                                       }
                                        
                                     return  4*x;
                                     
                       }

PHP continue statement

the php continue statement is used to stop the current iteration of a loop, and continues program flow with the beginning of the loop.

the continue statement only inside a while, do  . . . while, for or foreach loop.

the php continue statement never used within switch block.

 function   testbreak(){
     
                  for ($i = 0; $i < 6 ; $i++ ){
                  
                                           if ( $i < 4 ) {continue;}
                                           
        echo "<br/>" . "the value of i if not  continue the loop____".$i;
                                           
                                       }                             
                                     
                       }