in reply to Control Structures
In my code I often find structures of the form
which suggests to me that a better, more general design for a loop would put the test between "pre" and "post" blocks:while ( 1 ) { # yadda yadda last if some_condition(); # yadda yadda }
Both pre- and post-blocks get executed repeatedly until the test in the middle fails, at which point control passes to immediately after the post-block. The pre-block (together with the loop keyword) would be optional; omitting it results in the standard while-loop. Likewise, the post-block is optional; omitting produces the standard do-while loop.loop { # begin of enclosing block # pre-test code } while ( some_condition() ) { # post-test code; }
But Perl already gives a pretty close approximation for the attractive low price of an end-of-block redo:
{ # pre-code last if some_condition(); # post-code redo; }
the lowliest monk
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Control Structures ;-)
by Roy Johnson (Monsignor) on May 10, 2005 at 00:49 UTC | |
|
Re^2: Control Structures
by hossman (Prior) on May 10, 2005 at 07:27 UTC | |
by mstone (Deacon) on May 11, 2005 at 03:40 UTC | |
by hossman (Prior) on May 11, 2005 at 17:25 UTC | |
by BUU (Prior) on May 10, 2005 at 20:36 UTC | |
by halley (Prior) on May 11, 2005 at 13:49 UTC |