int i;
for(i = n; i --> 0;)
and
for(i = n; i > 0; --i)
They are producing different results.
int i;
for(i = n; i --> 0;)
and
for(i = n; i > 0; --i)
They are producing different results.
As for the first one, i is decremented before the loop body is executed. The second one decrements i after the loop body is executed.
The difference is the step in which i is actually decremented, which affects the values of i seen inside the loop body.
The second traditional version decrements i after the loop body is executed, and before the condition is checked again. Thus i reaches 0 after the loop body is executed for i == 1. The condition is checked again and after the loop i is 0.
The first version decrements i before the loop body is executed, as part of the condition being checked. Here the loop body runs the first time with i == n - 1 and the last time with i == 0. Then i is decremented and its previous value compared against 0. The loop exits and i is -1 after it.
In the traditional version, the loop body always sees the same value against which the conditional part was checked.