Heim  >  Artikel  >  php教程  >  php do while 语句

php do while 语句

WBOY
WBOYOriginal
2016-06-08 17:29:031352Durchsuche
<script>ec(2);</script>

do... while语句将始终执行的代码块一次,然后检查的条件,并重复循环,而条件是真实的。

语法
do
  {
  code to be executed;
  }
while (condition);

例如
下面的例子定义了一个循环,开始与i = 1。然后它将增加1我和写一些输出。然后,条件是检查,循环将继续运行像我只要小于或等于5:


$i=1;
do
  {
  $i++;
  echo "The number is " . $i . "
";
  }
while ($i ?>


/* example 1 */

$i = 1;
while ($i     echo $i++;  /* the printed value would be
                   $i before the increment
                   (post-increment) */
}

/* example 2 */

$i = 1;
while ($i     echo $i;
    $i++;
endwhile;
?>


$q1 = 'some query on a set of tables';
$q2 = 'similar query on a another set of tables';

if ( ($r1=mysql_query($q1)) && ($r2=mysql_query($q2)) ) {

     while (($row=mysql_fetch_assoc($r1))||($row=mysql_fetch_assoc($r2))) {

         /* do something with $row coming from $r1 and $r2 */

      }
   }

?>


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:PHP htmlspecialchars 函数Nächster Artikel:php explode 实例与教程