I thought that i--
is a shorthand for i = i - 1
, but I discovered that both evaluate different:
The i--
will be evaluated only after the loop condition is evaluated but before the statements within the loop. This is the decrement postfix operator. That means that initially the evaluation of the condition in the loop condition would be true
. This will fire the execution of the statements in the loop's body. When the statements in the loop's body will be executed, since the i
had be decremented by one, it would be equal to 0. Hence the evaluation of the loop condition would be false
and the statements in the loop's body will not be executed again.