Using i++ is less efficient than ++i.
The reason is that ++i immediately increments the variable whereas i++ makes a copy of the variable and increments the copy. So i++ is slower by the amount of time required to make that copy.
Example:
- int i = 10;
-
-
if (i++ == 11) //here i is 10. It won't be 11 until the next statement
-
{
-
}
-
int j = 10;
-
-
if (++j == 11) //here j is 11
-
{
-
-
}
-
If you are just incrementing a variable as in a loop then either i++ or ++i will work because you are not testing the variable but only incrementing it. Good programming will use ++i in these situations.