FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » why is it always an endless loop?
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
why is it always an endless loop? [message #186140] Mon, 16 June 2014 16:06 Go to next message
Mr Oldies is currently offline  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 Go to previous messageGo to next message
Markus Heinz is currently offline  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 Go to previous messageGo to next message
Derek Turner is currently offline  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 Go to previous messageGo to next message
Stephan Jaschke is currently offline  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 Go to previous messageGo to next message
Doug Miller is currently offline  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 #186149 is a reply to message #186140] Mon, 16 June 2014 17:27 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On Mon, 16 Jun 2014 12:06:26 -0400, richard wrote:

> $a="one"
> $b="one"
>
> while ($a=$b){echo "equal"; $b="two";)
>
> This simple code causes an endless loop.
> Why?

Because you keep ignoring something we tell you almost every week.

--
Denis McMahon, denismfmcmahon(at)gmail(dot)com
Re: why is it always an endless loop? [message #186151 is a reply to message #186140] Mon, 16 June 2014 18:09 Go to previous messageGo to next message
J.O. Aho is currently offline  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 Go to previous messageGo to next message
Luuk is currently offline  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 #186155 is a reply to message #186140] Mon, 16 June 2014 19:41 Go to previous messageGo to next message
Christoph Michael Bec is currently offline  Christoph Michael Bec
Messages: 207
Registered: June 2013
Karma: 0
Senior 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?

You may consider using a lint tool, such as
<http://www.icosaedro.it/phplint/phplint-on-line.html>. Parsing your
code with it points out 4 problems.

--
Christoph M. Becker
Re: why is it always an endless loop? [message #186156 is a reply to message #186140] Mon, 16 June 2014 20:45 Go to previous messageGo to next message
Tim Streater is currently offline  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 Go to previous messageGo to next message
Denis McMahon is currently offline  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 Go to previous messageGo to next message
Evan Platt is currently offline  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 #186163 is a reply to message #186140] Tue, 17 June 2014 06:20 Go to previous messageGo to next message
Arno Welzel is currently offline  Arno Welzel
Messages: 317
Registered: October 2011
Karma: 0
Senior Member
richard, 2014-06-16 18:06:

>
> $a="one"
> $b="one"
>
> while ($a=$b){echo "equal"; $b="two";)
>
> This simple code causes an endless loop.
> Why?

Because you STILL don't get the difference between the "=" operator
(assign) and "==" (compare)!


--
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de
http://fahrradzukunft.de
Re: why is it always an endless loop? [message #186164 is a reply to message #186140] Tue, 17 June 2014 06:22 Go to previous messageGo to next message
Arno Welzel is currently offline  Arno Welzel
Messages: 317
Registered: October 2011
Karma: 0
Senior Member
\|||/
(o o)
,~~~ooO~~(_)~~~~~~~~~,
| Please |
| don't feed the |
| TROLL! |
'~~~~~~~~~~~~~~ooO~~~'
|__|__|
|| ||
ooO Ooo
Re: why is it always an endless loop? [message #186165 is a reply to message #186164] Tue, 17 June 2014 15:13 Go to previous message
Denis McMahon is currently offline  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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: How to loop through the dates?
Next Topic: Authentication Framework?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 07:04:49 GMT 2024

Total time taken to generate the page: 0.02535 seconds