PHP鎺у埗缁撴瀯涔媤hile
鍐呭鎽樿
while 寰幆鏄 PHP 涓渶绠鍗曠殑寰幆绫诲瀷銆傚畠鍜 C 璇█涓殑 while 琛ㄧ幇寰椾竴鏍枫
鏂囩珷姝f枃
while
while 寰幆鏄 PHP 涓渶绠鍗曠殑寰幆绫诲瀷銆傚畠鍜 C 璇█涓殑 while 琛ㄧ幇寰椾竴鏍枫倃hile 璇彞鐨勫熀鏈牸寮忔槸锛
while (expr)
statement
while 璇彞鐨勫惈鎰忓緢绠鍗曪紝瀹冨憡璇 PHP 鍙 while 琛ㄨ揪寮忕殑鍊间负 TRUE 灏遍噸澶嶆墽琛屽祵濂椾腑鐨勫惊鐜鍙ャ傝〃杈惧紡鐨勫煎湪姣忔寮濮嬪惊鐜椂妫鏌ワ紝鎵浠ュ嵆浣胯繖涓煎湪寰幆璇彞涓敼鍙樹簡锛岃鍙ヤ篃涓嶄細鍋滄鎵ц锛岀洿鍒版湰娆″惊鐜粨鏉熴傛湁鏃跺欏鏋 while 琛ㄨ揪寮忕殑鍊间竴寮濮嬪氨鏄 FALSE锛屽垯寰幆璇彞涓娆¢兘涓嶄細鎵ц銆
鍜 if 璇彞涓鏍凤紝鍙互鍦 while 寰幆涓敤鑺辨嫭鍙锋嫭璧蜂竴涓鍙ョ粍锛屾垨鑰呯敤鏇夸唬璇硶锛
while (expr):
statement
...
endwhile;
涓嬮潰涓や釜渚嬪瓙瀹屽叏涓鏍凤紝閮芥樉绀烘暟瀛 1 鍒 10锛 <?php
/* example 1 */
$i = 1;
while ($i <= 10) {
echo $i++; /* the printed value would be
$i before the increment
(post-increment) */
}
/* example 2 */
$i = 1;
while ($i <= 10):
print $i;
$i++;
endwhile;
?>
while 寰幆鏄 PHP 涓渶绠鍗曠殑寰幆绫诲瀷銆傚畠鍜 C 璇█涓殑 while 琛ㄧ幇寰椾竴鏍枫倃hile 璇彞鐨勫熀鏈牸寮忔槸锛
while (expr)
statement
while 璇彞鐨勫惈鎰忓緢绠鍗曪紝瀹冨憡璇 PHP 鍙 while 琛ㄨ揪寮忕殑鍊间负 TRUE 灏遍噸澶嶆墽琛屽祵濂椾腑鐨勫惊鐜鍙ャ傝〃杈惧紡鐨勫煎湪姣忔寮濮嬪惊鐜椂妫鏌ワ紝鎵浠ュ嵆浣胯繖涓煎湪寰幆璇彞涓敼鍙樹簡锛岃鍙ヤ篃涓嶄細鍋滄鎵ц锛岀洿鍒版湰娆″惊鐜粨鏉熴傛湁鏃跺欏鏋 while 琛ㄨ揪寮忕殑鍊间竴寮濮嬪氨鏄 FALSE锛屽垯寰幆璇彞涓娆¢兘涓嶄細鎵ц銆
鍜 if 璇彞涓鏍凤紝鍙互鍦 while 寰幆涓敤鑺辨嫭鍙锋嫭璧蜂竴涓鍙ョ粍锛屾垨鑰呯敤鏇夸唬璇硶锛
while (expr):
statement
...
endwhile;
涓嬮潰涓や釜渚嬪瓙瀹屽叏涓鏍凤紝閮芥樉绀烘暟瀛 1 鍒 10锛 <?php
/* example 1 */
$i = 1;
while ($i <= 10) {
echo $i++; /* the printed value would be
$i before the increment
(post-increment) */
}
/* example 2 */
$i = 1;
while ($i <= 10):
print $i;
$i++;
endwhile;
?>
浠ヤ笂灏辨槸PHP鎺у埗缁撴瀯涔媤hile鐨勮缁嗗唴瀹癸紝鏇村淇℃伅璇峰叧娉∣D浜戝叾瀹冪浉鍏虫枃绔狅紒