Home > php教程 > PHP开发 > body text

The difference between break and continue in php learning

黄舟
Release: 2016-12-20 11:51:21
Original
2096 people have browsed it

Introducing to you another very important knowledge point in PHP learning. In flow control statements, we often use break and continue to transfer control statements. So what is the difference between the two.
1. First we introduce break. The break statement means to end the execution of the current conditional control statement such as if, switch or loop control statement such as while, for, foreach, etc. The break statement can accept an optional parameter to determine how many loops to break out of.
For example, the following switch:
switch($a){
case "1":
echo "The value passed is 1";
break;
case "2":
echo "The value passed is 2" ;
break;
}
2. The continue statement jumps out of the statement specifying the condition in this loop and continues to execute other loop statements. break is used to terminate the execution of statements under specified conditions, while the continue statement is used to jump out of the execution of a certain loop under specified conditions, while other loop statements continue to execute.
For example:
for($i=0;$i<5;$i++){
if($i == 3){
continue;
}
echo $i;
}
when $i=3 , will not output 3, jump out of this loop, and execute the next loop.
It is very important for PHP learners to master the difference between the two. Because in development we often have to make judgments about jumping out of control statements based on conditions. How to jump out requires mastering these two statements

The above is the difference between break and continue in PHP learning. For more related content, please pay attention to PHP Chinese website (www.php.cn)!


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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!