admin 发表于 2023-2-16 18:54:53

PHP中的while 和do-while

<div id="article_content" class="article_content clearfix">
      <link rel="stylesheet" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/kdoc_html_views-1a98987dfd.css">
      <link rel="stylesheet" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/ck_htmledit_views-6e43165c0a.css">
                <div id="content_views" class="htmledit_views">
                  <pre><code>while语句
<?php
/* 示例 1 */

$i &#61; 1;
while ($i <&#61; 10) {
    echo $i&#43;&#43;;/* 在自增前&#xff08;后自增&#xff09;打印的值将会是 $i */
}

/* 示例 2 */

$i &#61; 1;
while ($i <&#61; 10):
    print $i;
    $i&#43;&#43;;
endwhile;
?></code></pre>
<pre><code>goto跳出循环去做某事
<?php
for($i&#61;0,$j&#61;50; $i<100; $i&#43;&#43;) {
while($j--) {
    if($j&#61;&#61;17) goto end;
}
}
echo &#34;i &#61; $i&#34;;
end:
echo 'j hit 17';
?></code></pre>
<p></p>
<pre><code>do_while去做某事情
<?php
do {
    if ($i < 5) {
      echo &#34;i is not big enough&#34;;
      break;
    }
    $i *&#61; $factor;
    if ($i < $minimum_limit) {
      break;
    }
    echo &#34;i is ok&#34;;

    /* process i */

} while(0);
?></code></pre>
<p></p>
                </div>
      </div>
      <div id="treeSkill"></div>
页: [1]
查看完整版本: PHP中的while 和do-while