I'm well aware that in C++
int someValue = i++;
array[i++] = otherValue;
has different effect compared to
int someValue = ++i;
array[++i] = otherValue;
but every once in a while I see statements with prefix increment in for-loops or just by their own:
for( int i = 0; i < count; ++i ) {
//do stuff
}
or
for( int i = 0; i < count; ) {
//do some stuff;
if( condition ) {
++i;
} else {
i += 4;
}
}
In the latter two cases the ++i
looks like an attempt to produce smarty-looking code. Am I overseeing something? Is there a reason to use ++i
instead of i++
in the latter two cases?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…