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:

my $try= 0; my $max_tries = 100; while ($try < $max_tries) { last if foo($try); ++$try; } continue { next if ($try % 10); print "Still running after $try tries\n"; }

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?

-QM
--
Quantum Mechanics: The dreams stuff is made of


In reply to next in continue doesn't DWIM by QM

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.