Analysis of the difference between break and continue flow control instructions in PHP

  • 2020-05-05 11:00:33
  • OfStack

The following example illustrates
break is used to break out of the loop that is currently executing and not to continue the loop.
 
<?php 
$i = 0; 
while ($i < 7) { 
if ($arr[$i] == "stop") { 
break; 
} 
$i++; 
} 
?> 

continue immediately stops the current execution loop and returns to the conditional judgment of the loop to continue with the next loop.
 
<?php 
while (list($key,$value) = each($arr)) { 
if ($key == "zhoz"){ //  If the value of the query object is equal to zhoz This record will not be shown.  
continue; 
} 
do_something ($value); 
} 
//  example 2 
foreach ($list as $temp) { 
if ($temp->value == "zhoz") { 
continue; //  If the value of the query object is equal to zhoz This record will not be shown.  
} 
do_list; //  The records in the array are shown here  
} 
?> 

Note: the goto circular directive cannot be used in PHP.

Related articles: