php while语句问题

2025年03月19日 00:57
有3个网友回答
网友(1):

我用js运行了下,发现也是一样,说明这个逻辑是先判断是否小于10,再增加数值

网友(2):

在编程中x++和++x最终是一样的,不过在循环体中,x++是先取出x,再加1,++x先加后取

所以,改成++x才是先把x+1进行比较,否则是循环完了才会把x自增1

网友(3):

while 循环是 PHP 中最简单的循环类型。它和 C 语言中的 while 表现得一样。while 语句的基本格式是:

while (expr)
statement
/* example 1 */

$i = 1;
while ($i <= 10) {
echo $i++; /* the printed value would be
$i before the increment
(post-increment) */
}

/* example 2 */

$i = 1;
while ($i <= 10):
print $i;
$i++;
endwhile;
?>