爲什麼這段代碼不能正常工作?while循環中的多個條件無法正常工作
我們在這裏有一個無限循環! 我想在連續3個頂部或3個底部(實際上是硬幣的頂部和底部)時完成循環。你有一個翻蓋
<?php
$top = 0;
$bottom = 0;
$flipCount = 0;
while (($top < 3) || ($bottom < 3)) {
$flip = rand(0,1);
$flipCount ++;
if ($flip){
$top++;
$bottom = 0;
echo "<div>top</div>";
}
else {
$bottom++;
$top = 0;
echo "<div>bottom</div>";
}
}
echo "$flipCount flips!";
條件'(($ top <3)||(bottom <3))'總是'true',應該是'(($ top <3)&&($ bottom <3))' –
寫$ bottom而不是bottom在while循環條件下 –
@MahaDev我修復了它。這是一個打字錯誤。 –