* while loop
* 1. Entry judgment: while(condition){ #code }
* 2. Exit judgment: do { #code } while(condition)
echo 'while循环
'; for ($i=0; $i<10; $i++) { echo $i<9 ? $i.',' : $i; } echo '
';
//Use while to implement the above functions
//1. Entry judgment: judge whether the condition is successful before entering the loop, it is possible not to do it once
$i = 0; //初始条件 // $i = 10; //初始条件改为10,一次都不会执行 while ($i<10) { //循环条件 echo $i<9 ? $i.',' : $i; $i++; //更新条件,如果没有将进和死循环 } echo '
';
//2 .Exit judgment: judge whether the condition is successful after the loop execution ends, and execute the loop body at least once
$i = 0; //初始条件 // $i = 10; //初始条件改为20,但仍会执行一次 do { echo $i<9 ? $i.',' : $i; $i++; //更新条件,如果没有将进和死循环 } while ($i<10); //循环条件