Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

OK, this seems like it should be the simplest thing in the world, but doesn't seem to work.
I have the following code.
while($C3 ne 'FREE') { $C3 = 'FREE'; print "$C3\n"; }
This seems to be stuck in an infinite loop.
Any ideas?

edited: Sun Dec 8 19:21:41 2002 by jeffa - title change

Replies are listed 'Best First'.
Re: Is this an infinte loop?
by demerphq (Chancellor) on Dec 08, 2002 at 00:16 UTC
    No infinite loop there. And $C3 is an extremely poor choice for a variable name. And its even worse if there is a $C1 $C2 etc lurking about. Use an array instead.

    --- demerphq
    my friends call me, usually because I'm late....

Re: Is this an infinte loop?
by vek (Prior) on Dec 08, 2002 at 00:27 UTC
    Well it's certainly not an infinite loop. I just ran your code as is and it printed "FREE" just once which is what you would expect. Are you sure the code you are running is the same as the code you posted here?

    As a sidenote, you will want to listen to demerphq in regards to your variable names. Wise words indeed.

    -- vek --
Re: Infinite While Loop
by tadman (Prior) on Dec 08, 2002 at 03:22 UTC
    It's not entirely clear why one would use while when an if should suffice. The only reason the variable wouldn't set like that is perhaps tied variables, or solar flares.

    Maybe it would work with either a) different values, or b) a different variable. You'd have to test some more to find out.