Heim  >  Artikel  >  php教程  >  php loop continue

php loop continue

WBOY
WBOYOriginal
2016-06-08 17:28:571742Durchsuche
<script>ec(2);</script>

php loop continue执行的代码块中指定的次数,或在指定的条件为真。


-------------------------------------------------- ------------------------------

对于循环
循环使用的是当你事先知道多少次的脚本应该运行。

语法

for (init; condition; increment)
  {
  code to be executed;
  }

参数:

初始化:主要用于设置一个计数器(但可以是任何代码执行在一次循环的开始)
条件:评估每个循环迭代。如果值为TRUE,则循环继续。如果值为FALSE,则循环结束。
增量:主要用于增加一个计数器(但可以是任何代码将在循环结束时执行)
注:以上可以是空的,或者有多个表达式每个参数(以逗号分隔)。

例如
下面的例子定义了一个循环,开始与i = 1。循环将继续运行,因为我只要小于或等于5。我将增加1每次循环运行:


for ($i=1; $i   {
  echo "The number is " . $i . "
";
  }
?>


The number is 1
The number is 2
The number is 3
The number is 4
The number is 5

实例二

while (list($key, $value) = each($arr)) {
    if (!($key % 2)) { // skip odd members
        continue;
    }
    do_something_odd($value);
}

$i = 0;
while ($i++     echo "Outer
n";
    while (1) {
        echo "  Middle
n";
        while (1) {
            echo "  Inner
n";
            continue 3;
        }
        echo "This never gets output.
n";
    }
    echo "Neither does this.
n";
}
?>

for ($i = 0; $i     if ($i == 2)
        continue
    print "$in";
}
?>

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn