The first time it reaches while(n)
the value of n
is 3
.
Because only 0
counts a false, 3
counts are true and that statement amounts to while(3)
that is "while true" so the following line gets executed:
printf("%2d is true\n", n--);
That line outputs the value of n
.
If you don't understand why that is going to output that value go back a chapter or two and read up on printf(.)
. I don't know what book you're reading but I assume it follows a logical order and introduced output pretty early on.
That line also subtracts one from n (that's what n--
means).
If you don't understand that, again go back a bit.
That expression reduces n
by one but returns its value before the subtraction.
That results in the first line of output:
3 is true
Then the program loops back to the while condition. Now n
is 2
. But 2
still counts as true so the in-loop code (the first printf
) gets executed again giving:
2 is true
And ends with n
holding the value 1
. That leads to one further execution of the in-loop code giving
1 is true
Now that execution leaves with n
having the value 0
. That counts as false so the loop condition while(n)
is while(0)
which means "while false".
So execution bypasses the in-loop code and executes:
printf("%2d is false\n", n);
The leads to the line
0 is false
The rest of the program does a similar thing in reverse starting with n
having the value -3
and then incrementing it (by n++
) till again it hits false (n
being 0
).
That gives the lines
-3 is true
-2 is true
-1 is true
0 is false