while ? do...while ?
PHP ?? - While ??
??? ???? ?? ??? ??? true? ?? ?? ??? ?????.
PHP ??
??? ??? ? ??? ?? ??? ???? ???? ?? ??? ????. ? ??? ???? ?? ???? ?? ?? ??? ? ????.
PHP??? ??? ?? ?? ?? ?????. ?? ??? ? ? ??? ?? ??? ??? true? ? ??? ?????.
·????? for - ??? ?? ??? ?????. ??
·???? foreach - ??? ? ??? ?? ?? ??? ?????.
while ??while ??? ??? ????? ?????. ??? ??? ?? ?? ??? ?? ??. ??
while(??)
{??? ??;
}
??
?? ?? ?? ?? i? ?? 1($i=1;)? ?????.
??? i? 5?? ??? ?? ?? while ??? ?? ?????. ??? ??? ??? i? 1? ?????.
<html> <body> <?php $i=1; while($i<=5) { echo "The number is " . $i . "<br>"; $i++; } ?> </body> </html>
??:
??? 1
??? 2??? 3
??? 4 ??? 5
do...while ?
do...while ?? ??? ? ? ?? ??? ? ?????. ??? ??? ?, ?? ??? ?? ???? ??? ?????. ??
do { 要執(zhí)行的代碼; } while (條件);
??
?? ???? ?? ?? i? ?? 1($i=1;)? ?????.
?? ?? do...while ??? ?????. ??? ?? i? ?? 1? ???? ?? ?? ?????. ?? ??(i? 5?? ??? ??)? ?????. i? 5?? ??? ??? ??? ?? ?????.
<html> <body> <?php $i=1; do { $i++; echo "The number is " . $i . "<br>"; } while ($i<=5); ?> </body> </html>
??:
??? 2
??? 3??? 4
??? 5 ??? 6
???? ????
<?php //定義循環(huán)的初始值 $i=0; echo '<table width="800" border="1">'; while($i<100){ //輸出列0-99的列了 echo '<td>'.$i.'</td>'; //一定要加喲,不然死循環(huán)了 $i++; } echo '</table>'; ?>
???? ??? ???? ? ???? ?????. 2.
<?php $i=0; echo '<table width="800" border="1">'; while($i<100){ //0 - 9 為一行 //10 -19 為一行 //因此,每一行都能夠被10求默,如為為10的時候,應(yīng)該顯示行開始的標簽 if($i%10 == 0){ //為了隔行變色,每20,40,60每行的顏色是PHP學院的,因此我們又可以再進行一次取余運算 if($i%20==0){ echo '<tr>'; }else{ echo '<tr bgcolor="pink">'; } } echo '<td>'.$i.'</td>'; $i++; //同理,每一行結(jié)束是不是應(yīng)該有一個</tr>結(jié)束標簽?zāi)兀? if($i%10==0){ echo '</tr>'; } } echo '</table>'; ?>
??? ??? ??? ?????. ??: ?? ???. ?? ??(?? ?? ?? ??)
whie(1){
echo 1111.'<br />';}
do. ..while?
Do-while ??? while ??? ?? ?????, ???? ???? ?? ?? ??? ?? ? ??? ??? ????? ????. ?? while ???? ?? ???? do-while ?? ?? ? ? ????? ????(? ?? ?? ???? ???? ?????). ??? ?? while ????? ??? ?? ?? ????( ???? ???? ?? ?? ? ????, ??? FALSE?? ?? ??? ?? ?????.
do-while ???? ??? ??? ????: <?php
$i = 0;
do {
echo $i;
} while ($i > ; 0 );
?>
? ??? ??? ? ? ?????. ???? ? ?? ?? ?? ???? ??? ??? ? ?? ?? FALSE($i? ? ?? ?? ?????. 0??) ??? ?????.
Do While ???? while ???? ? ?? ???? ????. ???? ??? true?? ??? ???? do while? ?? ???? while? true?? ? ? ????? ????. .