Reputation: 295
I was looking through some C++ code today when I stumbled upon this:
while (c--) {
a = (a + 1) % n;
while(arr[a]) a = (a + 1) % n;
}
c was an integer. Don't while loops take boolean expressions to be evaluated? I know 1 and 0 are fine because they represent true and false, respectively, but in this case c was taking on values other than 0 and 1. What does this do?
Upvotes: 0
Views: 458
Reputation: 8144
Anything that isn't 0 is considered true, so this would loop until C=0.
Could just be a simple case of "using less code"
Upvotes: 1