I think the first time I saw an increment in a high level language was in a loop like

 for (j = 0; j < count; j++) { }

The existence of ++j was only a side node without immediate use case.

So maybe blame K&Rą for this implementation documentation causing a bias ultimately leading to an "it looks better" perception? (well most probably it even predates C ˛)

Anyway optimizing for such implantation details can bite you severely when processor technology advances.

For instance linearizing loops used to be a good idea till the memory access for the longer code was beaten by inline caches being able to hold the smaller loops in processor memory.

So who knows what comes next?

Personally I don't like post increment since it's a side effect sometimes causing weird undefined conditions, and in the world of concurrency side effects are the worst sin.

But in Perl at least I have to trust that it's optimized away in void and loop context.

Cheers Rolf

PS: Je suis Charlie!

updates

ą)

I found the oldest version in the net and it explicitly says:

This slightly more ornate example adds up the elements of an array: sum = 0; for( i=0; i<n; i++) sum = sum + array[i];

But actually ++i would work the same, this post-increment notation hides the fact that the increment is only executed at the end of the loop's body.

NB: like in Perl

For Loops Perl's C-style "for" loop works like the corresponding "while" +loop; that means that this: for ($i = 1; $i < 10; $i++) { ... } is the same as this: $i = 1; while ($i < 10) { ... } continue { $i++; }

˛) according to WP it was invented for B.


In reply to Re^7: quickness is not so obvious by LanX
in thread quickness is not so obvious by DanBev

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.