|Perl Monk, Perl Meditation|
next in continue doesn't DWIMby QM (Parson)
|on Nov 14, 2013 at 11:16 UTC||Need Help??|
QM has asked for the
wisdom of the Perl Monks concerning the following question:
I get bit by (next in continue) every now and then:
last, next, or redo may appear within a continue block; last and redo behave as if they had been executed within the main block. So will next, but since it will execute a continue block, it may be more entertaining.
Just curious if this is really useful, because it can lead to infinite loops that are hard to figure out. Sure, it's pretty obvious that it's an infinite loop, but it's not obvious that next is the cause:
As soon as ($try % 10) is true, next if ($try % 10) calls itself forever, as $try is never updated after that point. (This could be "solved" by using ($try++ % 10) instead of incrementing in the body, but this only prevents the infinite loop, and the code doesn't behave as intended.)
I would expect that a next from continue would go the the loop body, while a next from the body would go to continue.
Opinions on DWIM?