continue是在反复语句中,停止命令语句的实行并回到反复语句重新评价条件语句的控制构造。
语法构造 | 说明 |
---|---|
for( ; ; ) { if(expr) { stmt1; continue; } stmt2; } |
无限反复for语句,当if语句的表现形式为TRUE时实行命令语句1,依据continue语句移到for语句的最开始 |
<?php
for($i = 1; ; $i++) // infinite loop
{
if($i % 5)
continue; // go to the beginning of for loop
echo "$i\r\n"; // statement is executed if expression is FALSE
sleep(1);
}
?>
[result]
5
10
15
... (repetition)
<?php
$j = 0;
for($i = 0; ; $i++) // infinite loop(level 1)
{
sleep(1);
if($i)
echo "This is for statement \$i = $i\r\n"; // repeated by continue 2
while(1) // infinite loop(level 2)
{
$j++;
if(($j % 5) == 0)
continue 2; // go to the beginning of for loop
echo "$j, ";
sleep(1);
}
}
?>
[result]
1, 2, 3, 4, This is for statement $i = 1
6, 7, 8, 9, This is for statement $i = 2
11, 12, 13, 14, This is for statement $i = 3
... (repetition)