I'm going through some finer details of Perl and I came across the availability of an optional continue block available with use of a while conditional structure.

The examples I've found for its use go like this:

From Programming Perl 3rd ed.

while (my $line = <STDIN>) { $line = lc + $line; } continue { print $line; #still visible } # $line now out of scope here

From Elements of Programming with Perl

my $count = 0; while ( $count < 10 ) { print "$count\n"; } continue { $count++; }

The first example is nice for showing that the scope extends over the entire structure, and the second is nice for showing how to turn a while into an awkward looking for loop. I should point out that all references to the continue block explicitly say that it is a seldom used construct.

My curiosity is two-fold:

    In light of previous discussions showing that for loops are not as quick as while loops (sorry couldn't find the darn disscussion/benchmarks); Would utilization of continue'd blocked while loops be a more efficient substitue for for constructs?
    My other question deals with just plain curiosity of how/why/if others have situations where they find the continue block particularly convenient.

coreolyn


In reply to while 's 'continue' block by coreolyn

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.