Home > php教程 > PHP源码 > body text

continue break return函数用法与区别

WBOY
Release: 2016-06-08 17:27:10
Original
1136 people have browsed it
<script>ec(2);</script>

*/
$i =5;

 代码如下 复制代码
$sum =0;
for( $j =0;$j {
 if( $j == $i )
 {
  break;
 }
 else
 {
  $sum +=$j;
 }
}

echo $sum; //10

 代码如下 复制代码
$continueSum =0;
for( $i =0;$i {
 if( $i == 5 )
 {
  continue;
 }
 else
 {
  $continueSum +=$i;
 }
}
 代码如下 复制代码

echo $continueSum; //50


$a=2;


if( $a==2 )
{
 return $s=8;
}
else
{
 return $s=9;
}


echo $s;//没有什,我们把它写成函数看看


echo sv($a); //输了10

 代码如下 复制代码
function sv($a)
{
 if( $a==2 )
 {
  return 10;
 }
 else
 {
  return 11;
 }
}

/*
总结三者的区别:
 continue 跳出当前循环,并进入下次循环
 break 跳出当前的循环,往下执行其它代码
 return 终止操作,在return后面的代码都不被执行了。
 本站原创文章转载注明来源www.111cn.net/phper/php.html
*/

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