Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Perl style question: loops with postcondition

by Aristotle (Chancellor)
on Jun 28, 2002 at 15:49 UTC ( [id://178043]=note: print w/replies, xml ) Need Help??


in reply to Perl style question: loops with postcondition

A tricky question, and one that usually has me trying to avoid the need for a post condition in the first place.

LOOP: .. goto LOOP if is completely out of the question ever since I grew out of BASIC. :)

redo if uses an unnamed block that to me signals "short term lexical variables required for the next couple of lines", not "postcondition loop here" when I'm reading the code.

continue has the disadvantage of a massive performance hit, so I only resort to it when I need its special property that the continue-block is executed regardless of where or how the main loop's body was exited. Which so far, was never.

do while would be the natural way to go about it, but has the disadvantage that you cannot use next and co in the (non)loop body. It's ok for short loops though.

Thus, while(1) last if is what I'd do most of the time.

However, these calls are just mine; I can see that someone else might disagree with them. Basically, since there's no "real"/"official" postcondition loop construct in Perl, it is mostly up to you. The only thing I will "insist" on is to immediately forget the goto form - but I guess you knew that anyway.

Makeshifts last the longest.

  • Comment on Re: Perl style question: loops with postcondition

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://178043]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2025-05-12 02:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.