Whadda yer know. I made this same error 3 years ago, and despite being corrected, and accepting that correction from the ultimate authority, I'm still making it.

Does that say something about me? Or just confirm TimToady's reasoning for ditching the do{ ... } while construct.

For those not following along.

This

my $i = 0; while( $i < 5 ) { print ++$i; } 1 2 3 4 5

And this

my $i = 0; print ++$i while $i < 5; 1 2 3 4 5

Produce the same output.

And so do $i = 0; until( $i >= 5 ) { print ++$i }

And $i = 0; print ++$i until $i >= 5;

And $i=0; ++$i and print( $i ) while $i < 5;

And $i=0; ++$i, print( $i ) while $i < 5;

And even this $i=0; do{ ++$i; print( $i ) } while $i < 5;

But then suddenly, whilst $i=0; print( $i ) while $i++ < 5; this does.

This

$i=0; do{ print( $i ) } while $i++ < 5; 0 1 2 3 4 5

doesn't.


So, somewhere back there I've reached the conclusion that do{  } while is too subtle even for my tastes and stopped using it. As a result, I convinced myself that "Perl doesn't have a post-condition loop".

As you can see, I'm wrong. But for good reasons, and in line with those of some other people I respect, I'll continue to mentally deprecate it's usage.

With luck, this will act as an aide memoire to cause me not to voice my internal deprecation Perl does not have a post-condition loop out loud.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re^4: Comment a block that match a keyword by BrowserUk
in thread Comment a block that match a keyword by yorkwu

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.