Here's the dirty C trick in Java:
public class Loop { public static void main (String [] argv) { for (int i = 0; i < 10; i ++) { System . out . println (i); } } }

And here it is in AWK:

BEGIN {for (i = 0; i < 10; i ++) {print i}}

And here it is in LPC:

void loop () { int i; for (i = 0; i < 10; i ++) { write (i + "\n"); } }

It's not just C.

Feel free to find for my $i (map {$_ * 2} 0 .. 1000000 / 2) {$sum += $i} a bit strange, because it comes closer to the quoted while statement. But then, don't say that when we change the $i += 2 to $i ++ the alternative is a foreach. That would also be closer to the while.

I know the foreach is more efficient than the for, but only in the case of incrementing the variant by 1. The for() is far more flexible than the foreach(). The for() is a less error-prone, and easier way of writing the while.

Abigail


In reply to Re: extracting corresponding values from another array by Abigail-II
in thread extracting corresponding values from another array by Anonymous Monk

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.