如果正在计算的值等于另一个变量,我试图在达到指定的重复次数之前让循环停止。我在 if 语句中有一个中断,但是它似乎没有任何作用,因为它一直循环直到达到指定的最终值。
echo "<h4>iteration Stages</h4>\n";
// looping the math for each iteration
for ($i=1; $i <= $iterations ; $i++) {
$estimate = 0.5 * ($estimate + $number / $estimate);
if ($estimate == $real){
echo round($estimate, 2);
break;
} else {
echo round($estimate, 2);
echo " -- \n";
}
}