I use this code with php:
while (0 != $date1 || $this->counter < 5 ) {
// if ($this->true_cahce_failure ) {
$this->url= $this->adjust_url_with_www_add($this->url);
// $this->counter=2;
// }
$this->cache_debug("Date".$date1." ".$this->url,"Recursion ".$this->counter);
$date1 = $this->get_date();
$this->counter++;
}
$this->cache_debug("Date: ".$date1." ".$this->url,"Loop Done ");
Basically the loop should continue until either $date is not 0 or counter isn't bigger than 5. Sometimes the date1 has got 0 but sometimes not. When it doesn't it should return in the while evaluation, and stop the iteration. But it doesn't do so and the iteration continues.
It only stops with counter reaches 5. Why is that?
I think you want to use && in your condition instead of ||.
The way you've written it it will keep going if either condition is true, so it will only stop if they are both false.
EDIT: after reading your question more closely, I think you need to use
while (0 == $date1 && $this->counter < 5 ) {
It's likely not stopping because your $this->counter is still < 5 when $date1 is not 0. If you look at those statements in their true/false values, your while condition becomes:
while( false || true )
while $this->counter is < 5 and for any values of $date, which would make the execution continue.
You likely want to switch it to
while( 0==$date1 && $this->counter<5 )
Using && because you want both conditions to be true, not just one. Also switching the != to == when comparing the date to 0 so it will also stop when you have a non-0 date.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With