Home > Backend Development > PHP Tutorial > PHP: The difference between break and continue flow control instructions

PHP: The difference between break and continue flow control instructions

黄舟
Release: 2023-03-11 11:08:01
Original
1217 people have browsed it

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


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; // 这里显示
数组
中的记录 
} 
?>
Copy after login


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!

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