why is it always an endless loop? [message #186140] |
Mon, 16 June 2014 16:06 |
Mr Oldies
Messages: 241 Registered: October 2013
Karma: 0
|
Senior Member |
|
|
$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?
|
|
|
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: 0
|
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
|
|
|
Re: why is it always an endless loop? [message #186142 is a reply to message #186140] |
Mon, 16 June 2014 16:19 |
Derek Turner
Messages: 48 Registered: October 2010
Karma: 0
|
Member |
|
|
On Mon, 16 Jun 2014 12:06:26 -0400, richard wrote:
> 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?
because ($a=$b) sets $b to the same as $a and returns true. That's not
what you were trying to do, was it. And you have been told this a thousand
times before, haven't you?. And WTF has basic, which has different syntax
altogether got to do with it. HINT if you want to use PHP then write code
in (correct) php syntax.
|
|
|
Re: why is it always an endless loop? [message #186143 is a reply to message #186140] |
Mon, 16 June 2014 16:19 |
Stephan Jaschke
Messages: 1 Registered: June 2014
Karma: 0
|
Junior Member |
|
|
Am 16.06.2014 18:06, schrieb richard:
>
> $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?
>
= != == :-)
SCNR
|
|
|
Re: why is it always an endless loop? [message #186146 is a reply to message #186140] |
Mon, 16 June 2014 16:35 |
Doug Miller
Messages: 171 Registered: August 2011
Karma: 0
|
Senior Member |
|
|
richard <noreply(at)example(dot)com> wrote in news:qw7xoz3y22k8.h8pla1goojcr$.dlg@
40tude.net:
>
> $a="one"
> $b="one"
>
> while ($a=$b){echo "equal"; $b="two";)
>
> This simple code causes an endless loop.
> Why?
Because you screwed up again, Richard the Stupid, and made a mistake that you have made
many times in the past -- and obviously, just as many times, failed to learn from it.
|
|
|
|
Re: why is it always an endless loop? [message #186151 is a reply to message #186140] |
Mon, 16 June 2014 18:09 |
J.O. Aho
Messages: 194 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On 16/06/14 18:06, richard wrote:
>
> $a="one"
> $b="one"
>
> while ($a=$b){echo "equal"; $b="two";)
>
> This simple code causes an endless loop.
> Why?
try this one instead and you see why:
$a="one"
$b="one"
while($a=$b) {
echo "equal a='{$a}', b={$b}\n";
$b="two";
}
> As soon as $b is changed, they are no longer equal, yet the loop continues.
> This does not happen in BASIC.
For BASIC lacks == and ===
> If it is placement, where then should $b be placed?
It's your compare which is incorrect, I don't remember how many times
you have made the same mistake over and over again.
Don't complain about the answers in the thread, be happy that people
haven't added you to filters to not see your posts.
--
//Aho
|
|
|
Re: why is it always an endless loop? [message #186153 is a reply to message #186140] |
Mon, 16 June 2014 18:32 |
Luuk
Messages: 329 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On 16-6-2014 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?
>
Did someone already say to you that you asked this before?
|
|
|
|
Re: why is it always an endless loop? [message #186156 is a reply to message #186140] |
Mon, 16 June 2014 20:45 |
Tim Streater
Messages: 328 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
In article <qw7xoz3y22k8(dot)h8pla1goojcr$(dot)dlg(at)40tude(dot)net>, richard
<noreply(at)example(dot)com> wrote:
> $a="one"
> $b="one"
>
> while ($a=$b){echo "equal"; $b="two";)
>
> This simple code causes an endless loop.
No it doesn't. This will not even execute.
Then you wonder why you get bashed all the time.
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
|
|
|
Re: why is it always an endless loop? [message #186157 is a reply to message #186156] |
Mon, 16 June 2014 21:19 |
Denis McMahon
Messages: 634 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On Mon, 16 Jun 2014 21:45:48 +0100, Tim Streater wrote:
> In article <qw7xoz3y22k8(dot)h8pla1goojcr$(dot)dlg(at)40tude(dot)net>, richard
> <noreply(at)example(dot)com> wrote:
>
>> $a="one"
>> $b="one"
>>
>> while ($a=$b){echo "equal"; $b="two";)
>>
>> This simple code causes an endless loop.
>
> No it doesn't. This will not even execute.
>
> Then you wonder why you get bashed all the time.
Tim is write. The code that you wrote as an example will not execute. The
code that you think that you wrote will, and as has been pointed out
several times, contains an error that you have been told about many times
before.
--
Denis McMahon, denismfmcmahon(at)gmail(dot)com
|
|
|
Re: why is it always an endless loop? [message #186160 is a reply to message #186157] |
Tue, 17 June 2014 03:39 |
Evan Platt
Messages: 124 Registered: November 2010
Karma: 0
|
Senior Member |
|
|
On Mon, 16 Jun 2014 21:19:00 +0000 (UTC), Denis McMahon
<denismfmcmahon(at)gmail(dot)com> wrote:
> Tim is write. The code that you wrote as an example will not execute. The
> code that you think that you wrote will, and as has been pointed out
> several times, contains an error that you have been told about many times
> before.
richard is obviously a troll. No one but a troll would make statements
he makes, or make the same mistakes he makes over and over again. He
has - in legal groups - stated someone should be charged with
"deformation of character" dozens of times - maybe even more, going
back 5+ years. And each time, he's laughed at.
You would think you'd make that mistake ONCE.
--
To reply via e-mail, remove The Obvious and .invalid from my e-mail address.
|
|
|
|
|
Re: why is it always an endless loop? [message #186165 is a reply to message #186164] |
Tue, 17 June 2014 15:13 |
Denis McMahon
Messages: 634 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On Tue, 17 Jun 2014 08:22:20 +0200, Arno Welzel wrote:
> \|||/
> (o o)
> ,~~~ooO~~(_)~~~~~~~~~,
> | Please |
> | don't feed the |
> | TROLL! |
> '~~~~~~~~~~~~~~ooO~~~'
> |__|__|
> || ||
> ooO Ooo
Arno, I would dearly love to place richard on ignore, as would many other
people, but he has this habit of answering other people's questions,
invariably incorrectly, handing out the worst advice possible from his
years of accumulated ignorance, and presenting the resulting bullshit as
authoritative solutions for them.
Hence it is imperative that those of us who do know what we're talking
about remain vigilant to ensure that the innocent newbies who do attract
his attention receive an appropriate counterpoint.
Unfortunately, as that means we have to read his shit, it also means we
tend to respond to it.
--
Denis McMahon, denismfmcmahon(at)gmail(dot)com
|
|
|