<?php
function cover_EvenNumbers($obj){
$i=1;
while ($i <= $obj) {
if ($i % 2 ==0) {
echo "$i ";
}
$i++;
}
}
cover_EvenNumbers(100);
?>
do while和while的区别是,do里面的那个100%会跑。。。
<?php
function doWhile_Test($obj){
$i=1;
while ($obj ==2) {
if($i==25){
return;
}
echo "the obj is 2!!<br>";
$i++;
}
do {
echo "the obj is $obj<br>";
} while ($obj ==2);//while 循环里面写的要和下面do-while匹配上
}
doWhile_Test(2);
?>
the obj is 2!!
the obj is 2!!
the obj is 2!!
the obj is 2!!
the obj is 2!!
the obj is 2!!
the obj is 2!!
the obj is 2!!
the obj is 2!!
the obj is 2!!
the obj is 2!!
the obj is 2!!
the obj is 2!!
the obj is 2!!
the obj is 2!!
the obj is 2!!
the obj is 2!!
the obj is 2!!
the obj is 2!!
the obj is 2!!
the obj is 2!!
the obj is 2!!
the obj is 2!!
the obj is 2!!
the obj is 2!!
the obj is 2!!
the obj is 2!!
the obj is 2!!
the obj is 2!!
the obj is 2!!