在PHP中,break
在给定点退出循环。但是,是否有可能在给定的点强制循环跳转到下一个迭代,而不是完全退出它?本质:
for ($i = 0; $i < $foo; $i++){
if ($i == 1){
gotoNextIteration;
} else {
//do something else
}
}
使用continue
for ($i = 0; $i < $foo; $i++){
if ($i == 1){
continue;
} else {
//do something else
}
}
要么使用continue;
,要么也可以这样做
for ($i = 0; $i < $foo; $i++){
if ($i != 1){
//do something
}
}
你不需要其他任何东西
是…我已经为动态内容构建了许多类型的循环:
for ($i = 1; $i <= 20; $i++) {
if ($i == 1) {
// write table header
} else if ($i == 20) {
// write the table footer
} else {
// fill the table columns
}
}
这是一个基本示例,但我将其用于数据迭代(如图像库)和动态表等。但我对Abhik Chakraborty的回答鞠躬,因为我不熟悉"继续"这个词。我喜欢学习新东西。