I was browsing a GNUstep project on github and came across this little loop...
for(; i < 9; i+=1)
{
for(;j < 9; j+=1)
{
/* Inner loop code - snipped */
}
}
Most, but not all incremental operations were done using '+=1' 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.
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.
for(; i<10; i++)
{
/* inner loop code - snipped */
}
Now I've read this question, and it confirmed my suspicions - The compiler should be generating the same low-level code regardless of the syntax used.
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 'i++' without thinking - and I'm guessing that's natural for any coder, you just type it without thinking almost.
Am I missing something or is this "just because"? Is there any reason why you would mix both types of incrementing? If they both compile down to the same ASM then I would assume there's no situations when one performs better than the other.
Usually this happens when there are several programmers, each with his own coding preferences, and the project doesn't enforce strict coding style.
There is no difference.