As already mentioned by JavaFun, "B::Deparse" shows that perl compiles "while(){}" and "for(;;){}" to the same code, so "1" and "2" behave different, "3" and "4" are equal, "5" and "6" are also equal ...

#!/usr/bin/perl use B::Deparse; my $deparse = B::Deparse->new(); my $sub0 = sub { for(;;) {print}; }; my $sub1 = sub { while () {print}; }; my $sub2 = sub { while ( () ) {print}; }; my $sub3 = sub { print while (); }; my $sub4 = sub { print while ( () ); }; my $sub5 = sub { print until (); }; my $sub6 = sub { print until ( () ); }; foreach ( $sub0, $sub1, $sub2, $sub3, $sub4, $sub5, $sub6 ) { print $count++,":\nsub ", $deparse->coderef2text($_), "\n\n"; }

Program output:

0: sub { while (1) { print $_; } } 1: sub { while (1) { print $_; } } 2: sub { while (()) { print $_; } } 3: sub { print $_ while (); } 4: sub { print $_ while (); } 5: sub { print $_ until (); } 6: sub { print $_ until (); }

In reply to Re: while () vs. while (1) by nif
in thread while () vs. while (1) by perl5ever

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.