Home > php教程 > php手册 > body text

php中跳出函数break,continue,exit的使用与区别

WBOY
Release: 2016-06-12 20:07:47
Original
834 people have browsed it

1.break跳出代码片段,结束这个循环 

2.continue结束当前片段,结束这次循环,继续下一次循环

3.exit 结束整个PHP代码

 
<span style="font-family: tahoma, arial, helvetica, sans-serif; font-size: 14px;"><span style="line-height: 19px;">break的作用是跳出这个循环(如果这个break或者continue在循环中的if语句里面,不是跳出if语句,而是跳出循环语句),</span><span style="line-height: 19px;">执行这个循环的大括号以后的语句,</span></span>
Copy after login
<span style="font-family: tahoma, arial, helvetica, sans-serif; font-size: 14px;"><span style="line-height: 19px;">break在循环语句中是这样,在switch语句用功能也是这样的,而continue是当条件满足的时候不执行这个循环后面的语句,从这个循环的开始重新执行。</span></span>
Copy after login
 
<?php   
/* php的break,continue,return 的简单区别代码 */   
$i = 1;     
while (true) { // 这里看上去这个循环会一直执行     
    if ($i==2) {// 2跳过不显示     
        $i++;     
        continue;     
    } else if ($i==5) {// 但到这里$i=5就跳出循循环了     
        break;     
    } else {     
        echo $i . '<br>';     
    }     
    $i++;     
}     
exit;     
     
echo '这里不输出'; 
?>
Copy after login

 

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!