Note that there are some explanatory texts on larger screens.

plurals
  1. POObjective-C: Mixed methods of incrementing - i++ vs i+=1
    primarykey
    data
    text
    <p>I was browsing a <a href="https://github.com/michaelwisely/GNUstep-Sudoku/blob/master/puzzleBoard.m" rel="nofollow noreferrer">GNUstep project</a> on github and came across this little loop...</p> <pre><code>for(; i &lt; 9; i+=1) { for(;j &lt; 9; j+=1) { /* Inner loop code - snipped */ } } </code></pre> <p>Most, <em>but not all</em> incremental operations were done using '<em>+=1</em>' in the source code; which would make sense if it was consistent. If it was consistent I would put it down to simple personal preference, or even readability. </p> <p>However, for a project that appears to have been worked upon by one person (it is, after all, a simple sudoku game) the differing style of incremental operations has got me a bit curious.</p> <pre><code>for(; i&lt;10; i++) { /* inner loop code - snipped */ } </code></pre> <p>Now I've read <a href="https://stackoverflow.com/questions/6509707/incrementing-x-vs-x-1">this question</a>, and it confirmed my suspicions - <strong>The compiler should be generating the same low-level code regardless of the syntax used</strong>.</p> <p>This got me pondering whether it's best practice or style guidelines, but the same coder has used the both methods of incrementing. Personally speaking, I use '<em>i++</em>' without thinking - and I'm guessing that's natural for any coder, you just type it without thinking almost.</p> <p><strong>Am I missing something or is this "<em>just because</em>"? Is there any reason why you would mix both types of incrementing?</strong> If they both compile down to the same ASM then I would assume there's no situations when one performs better than the other.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload