Closed Thread Icon

Topic awaiting preservation: I pity 'da Perl loop dat runs three times.. (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12384" title="Pages that link to Topic awaiting preservation: I pity &amp;#039;da Perl loop dat runs three times.. (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: I pity &#039;da Perl loop dat runs three times.. <span class="small">(Page 1 of 1)</span>\

 
Petskull
Maniac (V) Mad Scientist

From: 127 Halcyon Road, Marenia, Atlantis
Insane since: Aug 2000

posted posted 08-27-2002 20:44

um.... 'why the fuck does this run only 3 times?(???)'-- my emphatic comment pretty much sums it up

for($i = '0',$i == '10',$i++){ # WHY THE FUCK DOES THIS RUN ONLY 3 TIMES????
print "\n1";
print "-=-$i";
}

let it be known that it runs just fine- however- only three times... dunno why...

btw, $i will equal '1' each of those times...

This make any sense to you?


Code - CGI - links - DHTML - Javascript - Perl - programming - Magic - http://www.twistedport.com
ICQ: 67751342

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 08-27-2002 21:40

Nearly.

You're using commas instead of semi-colons.

So this has the same effect as

for($i = '0',$i == '10',$i++; /* no condition */; /*no iteration*/ ){
print "\n1";
print "-=-$i";
}

(forgive my C style comments)

So it sets $i to '0', compares that to '10', throwing away the value, and then increments $i to 1. Then it prints 1 a few times. Now, I'm not sure why it stops after the third time. Since there's no condition, I'd assume it would never stop.

I think this is what you meant:

for($i = 0,$i != 10,$i++)
... etc ...

notice I changed the == to != (since $i doesn't start equal to 10, it will terminate immediately) and the strings to numbers.

Petskull
Maniac (V) Mad Scientist

From: 127 Halcyon Road, Marenia, Atlantis
Insane since: Aug 2000

posted posted 08-28-2002 16:17

for($i = 0;$i > 10;$i++){ # WHY THE FUCK DOES THIS RUN ONLY 3 TIMES????
print "\n1";
print " $i";
}

now, that doesn't work, because I've been looking at it with the wrong approach. The following DOES work:

for($i = 0;$i < 10;$i++){ # Hey, it runs now...
print "\n1";
print " $i";
}

aparently, my estimation of the for function had been flawed- It doesn't run until the condition is true, it will loop until the condition is false and THEN it will exit....

..well, what do you know, earned a new brain cell...



Code - CGI - links - DHTML - Javascript - Perl - programming - Magic - http://www.twistedport.com
ICQ: 67751342

« BackwardsOnwards »

Show Forum Drop Down Menu