【发布时间】:2014-02-12 08:42:07
【问题描述】:
<!DOCTYPE html>
<html>
<head>
<title>A loop of your own</title>
<link type='text/css' rel='stylesheet' href='style.css'/>
</head>
<body>
<?php
//Add while loop below
$hello = true;
while($hello = true):
{
echo "Loop is runnin";
for($i = 0; $i <= 3; $i++)
{
$hello = false;
}
}
endwhile
?>
</body>
</html>
我的错误是:无限循环。
我该如何解决这个问题?我正在练习;-)
我想要一个while循环中的for循环,代码必须说3次“循环正在运行”然后进行
变量 $hello false。
$hello = true;
while($hello == true):
echo "Loop is runnin";
for($i = 0; $i < 3; $i++)
{
$hello = false;
}
endwhile;
这是结果,但如果你们有敏锐的眼光,你会看到它,for 循环将只运行一次:p 因为它会尝试将 $hello 3x 设置为 false。
但是谢谢大家回答我的问题;)
【问题讨论】:
-
1.
:在 while 语句之后在做什么? 2. $hello == true 是逻辑表达式,$hello = true 是赋值。你需要第一个。 -
@sashkello 它正在开始一个另一种while语法。
-
@deceze 在那种情况下,那些花括号在做什么? ;)
-
@deceze 应该是或者:)
-
@PeeHaa 不多,但它们也不碍事。这只是一个多余的群体。
标签: php if-statement for-loop while-loop