I thought that i--
is a shorthand for i = i - 1
, but I discovered that both evaluate different:
i--
is not the same as i=i-1
, when used in a loop.
i--
will be evaluated after the condition, but before the loop contents are run, whereas i=i-1
will be evaluated before the condition, so will evaluate to false.
I guess in that respect --i
is more similar to i=i-1
, as it is also evaluated prior to the condition.
You can think of
while (i--) {...}
As being equivalent to
while (i = i - 1, i + 1) {...}