Search code examples
c++while-looppostfix-operator

Postfix operators in while loops


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?


Solution

  • 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"