It is clearly defining the behavior of the linked program, and not knowing it would evaluate like that would probably be the source of another off-by-one error.
Because making it so that's significant behaviour is more likely to result in errors than making distinct statements and makes it harder to modify the code for special cases that may exist in the future.
Like the more clear way of writing this would be
for (x = 9; x >= 0; x--)
This clearly shows that 9 is the first value of x in the loop, it stops when x goes negative and each time x goes down by 1.
Not quite. It decrements then performs the comparison with the non decremented value. The decrement always happens before the comparison, but whether it compares with the current or previous value of x depends on the use of prefix or postfix decrement.
View all comments
Show parent comment
12
u/mydoglixu Feb 21 '20
In C++, would this increment before or after the comparison to 0?