i++ vs ++i
The ++ denotes when i is incremented in relation to evaluating it’s value for the expression.
++i : The value of i is incremented before we actually retrieve and use it.
i++ : The value of i is incremented after we have already retrieved and used it.
In a for loop, it is slightly more efficient to use ++i in terms of assembly instructions (1-2 orders less), because the flow operates the same either way:
test the condition
if it is false, terminate
if it is true, execute the body
execute the incrementation step
This means that “++i” should be used as the default for all incrementation operations (loop or otherwise) unless there is a specific need to increment -after- evaluation.
Last changeda month ago