时间:2021-07-01 10:21:17 帮助过:15人阅读
for (expr1; expr2; expr3)
statement
<?php
for (;;) {
//放置需要不断执行的语句
}
?>
<?php
for (;;) {
//如果是公元2199年,则跳出循环
if (date('Y') == '2199') {
break;
}
}
?>
<?php
if (isset($i)) {
unset($i);
if ((int) date('') < 2008) {
$i = 0;
} else {
$i = 1;
}
} else {
$i =3;
}
for (;$i < 10;$i ) {
echo $i;
}
?>
<?php
for ($i = 0, $j = 10;$i <= 10;$i , $j--) {
echo "$i $j = 10\r\n";
}
?>
0 10 = 10
1 9 = 10
2 8 = 10
3 7 = 10
4 6 = 10
5 5 = 10
6 4 = 10
7 3 = 10
8 2 = 10
9 1 = 10
10 0 = 10
<?php
//计算1-5的累加结果,斌值到$j
for ($i = 1,$j = 0; $i <= 5;$j = $i );
echo $j;
//计算1-5的阶乘结果,斌值到$j
for ($i = 1,$j = 1; $i <= 5;$j *= $i );
echo $j;
?>