Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Welcome to the Monastery
 
PerlMonks  

Re^2: Don't print on the last loop

by calin (Deacon)
on Jun 13, 2005 at 16:20 UTC ( [id://466282]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Re: Don't print on the last loop
in thread Don't print on the last loop

Another idea is to unroll the first iteration of the loop. This way you don't have to test for a flag on subsequent iterations. I believe this is the correct approach optimisation-wise - if one condition is true only once and then guaranteed false for the next 1.000.000 times, checking it programatically (and doing other stuff like modifying the flag variable) 1.000.001 times is a waste. Pseudocode:

if ( CONDITION ) { do_iteration(); while ( CONDITION ) { print ",\n"; do_iteration(); } }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://466282]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.