![]() |
|
"be consistent" | |
PerlMonks |
Re: Perl style question: loops with postconditionby Aristotle (Chancellor) |
on Jun 28, 2002 at 15:49 UTC ( [id://178043]=note: print w/replies, xml ) | Need Help?? |
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.
In Section
Seekers of Perl Wisdom
|
|