Home  >  Article  >  php教程  >  continue break return函数用法与区别

continue break return函数用法与区别

WBOY
WBOYOriginal
2016-06-08 17:27:101137browse
<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
*/

Statement:
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