【发布时间】:2017-06-05 22:53:50
【问题描述】:
我希望有人能在这里帮助我。我看了看,发现有人遇到了同样的问题: Do-While Loop with Multiple Conditions
但是我已经检查过了,看不到哪里出错了
这是我的代码:
$x=0;
$y=0;
do {
$x = rand(0,5);
$y++;
} while ($x!=5 || $y<=5);
所以我期待以下内容:当 X 不是 == 5 或 y 大于 5 时代码停止。但是我得到的结果是 x=5 和 y=>5
为了验证理论,我将代码更改为:
$x=0;
$y=0;
echo'<br />--x-y';
do {
$x = rand(0,5);
$y++;
echo'<br />--'.$x.'-'.$y;
if($y>5)
echo"-I should finish here";
} while ($x!==5 || $y<=5);
echo "<br />x=".$x;
echo "<br />y=".$y;
在一种情况下,我最终得到了:
--x-y
--5-1
--3-2
--4-3
--4-4
--2-5
--4-6-I should finish here
--1-7-I should finish here
--3-8-I should finish here
--3-9-I should finish here
--3-10-I should finish here
--3-11-I should finish here
--5-12-I should finish here
x=5
y=12
关于我哪里出错了有什么建议吗?
【问题讨论】:
标签: while-loop multiple-conditions