首页 > php代码 > php while loop next

php while loop next

php while loop next

循环执行的代码块中指定的次数,或在指定的条件为真。

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

PHP的循环

很多时候,当您编写代码,您希望相同的代码块来运行十多年,再行。而不是添加在脚本中我们可以使用循环来执行这样的任务数几乎相等线。

在PHP中,我们有以下循环语句:

同时通过一个代码块 - 循环,而指定的条件为真

不...而 - 遍历一个代码块一次,然后重复像长循环指定的条件为真

为 - 循环通过一个代码块中指定的次数

Foreach源 - 通过对每个元素的代码块循环中的一个数组

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

while循环

while循环执行的代码块,而条件是正确的。

语法

while (condition)
{
    code to be executed;
}

例如

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

html>

<body>

<?php
$i=1;
while($i<=5)
{
  echo "The number is " . $i . "<br />";
  $i++;
}
?>

</body>

</html> 

The number is 1

The number is 2

The number is 3

The number is 4

The number is 5


本文地址:http://www.phprm.com/code/php_while_loop_nex.html

转载随意,但请附上文章地址:-)

标签:none

发表留言