设为首页 - 加入收藏 ASP站长网(Aspzz.Cn)- 科技、建站、经验、云计算、5G、大数据,站长网!
热搜: 创业者 手机 数据
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php continue和break流程控制语名用法

发布时间:2022-06-24 12:42 所属栏目:121 来源:互联网
导读:continue:continue 在循环结构用用来跳过本次循环中剩余的代码并开始执行下一次循环. 注:注意在 php 中 switch 语句被认为是作为 continue 目的的循环结构.continue 接受一个可选的数字参数来决定跳过几重循环到循环结尾. ?php while (list($key,$value) = e
  continue:continue 在循环结构用用来跳过本次循环中剩余的代码并开始执行下一次循环.
 
  注:注意在 php 中 switch 语句被认为是作为 continue 目的的循环结构.continue 接受一个可选的数字参数来决定跳过几重循环到循环结尾.
 
  <?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; // 这里显示数组中的记录  
  }  
  ?>
  break:break 结束当前 for,foreach,while,do..while 或者 switch 结构的执行,break 可以接受一个可选的数字参数来决定跳出几重循环.
 
  <?php
  $arr = array ('one', 'two', 'three', 'four', 'stop', 'five');
  while (list (, $val) = each ($arr)) {
     if ($val == 'stop') {
         break;    /* you could also write 'break 1;' here. */
     }
     echo "$val<br>n";
  }
  
  /* using the optional argument. */
  
  $i = 0;
  while (++$i) {
     switch ($i) {
     case 5:
         echo "at 5<br>n";
         break 1;  /* exit only the switch. */
     case 10:
         echo "at 10; quitting<br>n";
         break 2;  /* exit the switch and the while. */
     default:
         break;
     }
  }
  ?>
  实例二:
 
  <?php  
  $i = 0;  
  while ($i < 7) {  
  if ($arr[$i] == "stop") {  
  break;  
  }  
  $i++;  
  }  
  ?> 。

(编辑:ASP站长网)

    网友评论
    推荐文章
      热点阅读