In the commonly used for and
foreach loops in php, we often encounter conditional judgment or abort the loop. The processing method mainly uses two process control instructions, break and continue. Now the main differences will be explained.
The following examples illustrate
break is used to jump out. The currently executing loop will no longer continue to execute the loop.
The code is as follows:
<?php $i = 0; while ($i < 7) { if ($arr[$i] == "stop") { break; } $i++; } ?>
continue Immediately stops the current execution loop and returns to the condition judgment point of the loop to continue the next loop.
The code is as follows:
<?php while (list($key,$value) = each($arr)) { if ($key == "zhoz"){ // 如果 查询 到对象的值等于zhoz,这条记录就不会显示出来了。 continue; } do_something ($value); } // 例子2 foreach ($list as $temp) { if ($temp->value == "zhoz") { continue; // 如果查询到对象的值等于zhoz,这条记录就不会显示出来了。 } do_list; // 这里显示 数组 中的记录 } ?>
Note: The goto loop instruction cannot be used in PHP.
The above is the detailed content of PHP: The difference between break and continue flow control instructions. For more information, please follow other related articles on the PHP Chinese website!