5 comments

  • kenferry47 minutes ago
    I know it&#x27;s &quot;too clever&quot;, but if I&#x27;m writing code no one else will ever see,<p><pre><code> while (i --&gt; 0) { &#x2F;&#x2F; use array[i] } </code></pre> easy to read (if not understand), and correct!
    • krackers40 minutes ago
      Oh I remember this from the classic SO post, but it was just presented as a funny trick. I never realized that it solves the issue mentioned in the article and there is a legitimate use-case for post-decrement in the comparison itself.<p><a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;1642028&#x2F;what-is-the-operator-in-c-c" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;1642028&#x2F;what-is-the-oper...</a>
    • viega32 minutes ago
      I always use unsigned values and do:<p><pre><code> while (i-- != 0) { ... } </code></pre> It&#x27;s more clear than the most idiomatic way, which is to drop the explicit comparison:<p><pre><code> while (i--) { ... } </code></pre> All of it is better than the clunky old for-loop syntax.
    • stephencanon45 minutes ago
      Always.<p>(Hi Ken!)
  • MaulingMonkey1 hour ago
    I prefer:<p><pre><code> const size_t n = 10; for (size_t i = n; i --&gt; 0;) { std::cout &lt;&lt; i &lt;&lt; &quot;\n&quot;; }</code></pre>
    • hedgehog55 minutes ago
      That&#x27;s a certain kind of taste... I checked out your home page, game dev, check, and this work of art is worth linking (no irony, I love it):<p><a href="http:&#x2F;&#x2F;maulingmonkey.com&#x2F;brainfuck&#x2F;" rel="nofollow">http:&#x2F;&#x2F;maulingmonkey.com&#x2F;brainfuck&#x2F;</a>
    • ranger_danger55 minutes ago
      Cute but wouldn&#x27;t work with ssize_t :)<p>VHDL&#x27;s array&#x2F;vector syntax actually works a similar way:<p>-- gives 0, 1, 2, 3:<p>for i in 0 to 3 loop<p>-- gives 3, 2, 1, 0:<p>for i in 3 downto 0 loop<p>-- Source - <a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;a&#x2F;7642026" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;a&#x2F;7642026</a> -- Posted by Kerrek SB -- Retrieved 2026-10-29, License - CC BY-SA 3.0
      • fourthark29 minutes ago
        Does work with ssize_t, just not necessary.
        • ranger_danger0 minutes ago
          Depends on your definition of &quot;work&quot;.<p>For me it does not work because I&#x27;d want to use it with values &lt; 0, but the for loop checks for &gt; 0, so I would have to modify that first.
  • abstractspoon2 days ago
    I&#x27;ve been using this method for more than 30 years!
  • lanmu11 minutes ago
    [flagged]
  • rpsworld1 hour ago
    [flagged]