[英]PHP: Issue with while loop condition
I have the following code, unfortunately it's looping infinity but I can't understand why : 我有以下代码,很遗憾,它循环无限,但我不明白为什么:
$tot_age is
set to 604245119 $tot_age is
设置为604245119
while ($tot_age > 536467742) {
$tot_age - 31536000;
if ($tot_age < 536467742 ) {
// do something
break;
}
}
So what I'm attempting to here is the following. 所以,我在这里尝试的是以下内容。 If $tot_age
is greater than 17 years, iterate through the loop and minus 12 months from $tot_age. 如果$tot_age
大于17年,请遍历循环,并从$ tot_age减去12个月。 I'm then attempting to break out of the loop at the point which $tot_age is less than 17 years. 然后,我尝试在$ tot_age不到17年的时候打破循环。 I'll apply some logic here too. 我也会在这里应用一些逻辑。
Can anyone see an issue here? 有人可以在这里看到问题吗? Thanks 谢谢
Use it like this: 像这样使用它:
while ($tot_age > 536467742) {
$tot_age = $tot_age - 31536000;
if ($tot_age < 536467742 ) {
// do something
break;
}
}
第二行应显示为
$tot_age = $tot_age - 31536000;
Youre not changing the value of tot_age in the loop, you're just making an empty statement. 您没有在循环中更改tot_age的值,只是在做一个空语句。 Change: 更改:
$tot_age - 31536000;
to: 至:
$tot_age = $tot_age - 31536000;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.