On 27/06/2013 16:03, Shawn H Corey wrote:
On Thu, 27 Jun 2013 07:45:17 -0700
Jim Gibson <jimsgib...@gmail.com> wrote:
Note that the statement modifier syntax allows you to write a
do-while or do-until loop, where at least one pass is made through
the loop before the loop termination test is performed:
do {
…
} while condition();
The while here is a statement modifier, and the do{} is a single
statement with one or more internal statements grouped as one.
Please don't use a do...while "loop". Technically, it's not a loop and
`last`, `next`, and `redo` won't work as you would expect. They will
either jump back to the last `for` or `while` loop, or exit the
subroutine.
That advice is unnecessarily prescriptive. The best you can say is that
it is as well to be aware of those restrictions when using the
do...while construct. I hope you can refrain from ordering people about.
do...while is less likely to be used together with embedded flow-control
commands, because it is a very specific loop structure on its own.
Without it the loop would have to be written
while () {
CODE;
last if CONDITION;
}
which is unnecessarily ugly. Or even worse
CODE;
while (CONDITION) {
CODE;
}
which is unadvised because of the repetition of identical code sequences.
Far better to use just
do {
CODE;
} while CONDITION;
and bear in mind the provisos that you list.
Rob
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/