PHP鎺у埗缁撴瀯涔媎o-while

鍐呭鎽樿
o-while 鍜 while 寰幆闈炲父鐩镐技锛屽尯鍒湪浜庤〃杈惧紡鐨勫兼槸鍦ㄦ瘡娆″惊鐜粨鏉熸椂妫鏌ヨ屼笉鏄紑濮嬫椂銆傚拰姝h鐨 while 寰幆涓昏鐨勫尯鍒槸 do-while 鐨勫惊鐜鍙ヤ繚璇佷細鎵ц涓娆★紙琛ㄨ揪寮忕殑鐪熷煎湪姣忔寰幆缁撴潫鍚庢鏌ワ級锛岀劧鑰屽湪姝h鐨 while 寰幆涓氨涓嶄竴瀹氫簡锛堣〃杈惧紡鐪熷煎湪寰幆寮濮嬫椂妫鏌ワ紝濡傛灉涓寮濮嬪氨涓 FALSE 鍒欐暣涓惊鐜珛鍗崇粓姝級銆
鏂囩珷姝f枃

o-while 鍜 while 寰幆闈炲父鐩镐技锛屽尯鍒湪浜庤〃杈惧紡鐨勫兼槸鍦ㄦ瘡娆″惊鐜粨鏉熸椂妫鏌ヨ屼笉鏄紑濮嬫椂銆傚拰姝h鐨 while 寰幆涓昏鐨勫尯鍒槸 do-while 鐨勫惊鐜鍙ヤ繚璇佷細鎵ц涓娆★紙琛ㄨ揪寮忕殑鐪熷煎湪姣忔寰幆缁撴潫鍚庢鏌ワ級锛岀劧鑰屽湪姝h鐨 while 寰幆涓氨涓嶄竴瀹氫簡锛堣〃杈惧紡鐪熷煎湪寰幆寮濮嬫椂妫鏌ワ紝濡傛灉涓寮濮嬪氨涓 FALSE 鍒欐暣涓惊鐜珛鍗崇粓姝級銆

do-while 寰幆鍙湁涓绉嶈娉曪細 <?php
$i = 0;
do {
   echo $i;
} while ($i > 0);
?>

浠ヤ笂寰幆灏嗘濂借繍琛屼竴娆★紝鍥犱负缁忚繃绗竴娆″惊鐜悗锛屽綋妫鏌ヨ〃杈惧紡鐨勭湡鍊兼椂锛屽叾鍊间负 FALSE锛$i 涓嶅ぇ浜 0锛夎屽鑷村惊鐜粓姝€

璧勬繁鐨 C 璇█鐢ㄦ埛鍙兘鐔熸倝鍙︿竴绉嶄笉鍚岀殑 do-while 寰幆鐢ㄦ硶锛屾妸璇彞鏀惧湪 do-while(0) 涔嬩腑锛屽湪寰幆鍐呴儴鐢 break 璇彞鏉ョ粨鏉熸墽琛屽惊鐜備互涓嬩唬鐮佺墖娈电ず鑼冧簡姝ゆ柟娉曪細 <?php
do {
    if ($i < 5) {
        echo "i is not big enough";
        break;
    }
    $i *= $factor;
    if ($i < $minimum_limit) {
        break;
    }
    echo "i is ok";

    /* process i */

} while(0);
?>

濡傛灉杩樹笉鑳界珛鍒荤悊瑙d篃涓嶇敤鎷呭績銆傚嵆浣夸笉鐢ㄦ鈥滅壒鎬р濅篃鐓ф牱鍙互鍐欏嚭寮哄ぇ鐨勪唬鐮佹潵銆


浠ヤ笂灏辨槸PHP鎺у埗缁撴瀯涔媎o-while鐨勮缁嗗唴瀹癸紝鏇村淇℃伅璇峰叧娉∣D浜戝叾瀹冪浉鍏虫枃绔狅紒



鏈枃URL锛http://www.odweb.cn/news_show.html?id=78