Re: why is it always an endless loop? [message #186141 is a reply to message #186140] |
Mon, 16 June 2014 16:17 |
Markus Heinz
Messages: 1 Registered: June 2014
Karma:
|
Junior Member |
|
|
Hello.
On 2014-06-16 18:06, richard wrote:
>
> $a="one"
> $b="one"
>
> while ($a=$b){echo "equal"; $b="two";)
>
> This simple code causes an endless loop.
> Why?
>
> As soon as $b is changed, they are no longer equal, yet the loop
continues.
> This does not happen in BASIC.
> If it is placement, where then should $b be placed?
>
You have to change the loop condition to
while ($a === $b)
Otherwise you assign the value of $b to $a if you use only one "=".
Regards
Markus
|
|
|