Concerning the following usage, i’m confused how –i evaluates to true and what determines when the loop exits:
while (--i) {
k = p[i];
p[i] = p[j = random() % B];
p[j] = k;
}
if as I understand it the — prefix is decrementing the value of i before it begins the loop, are we then evaluating true=value > 1 and false=0 and thus the loop exits when the value reaches 0? Perhaps I’ve answered my own question, but if anyone could enlighten me on this. Also, how would this loop behave if the decrement operator was a suffix?
Yes, prefix decrement will decrement the variable, then the returned value (the result) from the expression is used for the condition.
The loop terminates when
ibecomes1(and it decremented to0, the returned value of the condition).