This code first compares x and 0 and then decrement x. (Also said in the first answer: You're post-decrementing x and then comparing x and 0 with the >
operator.) See the output of this code:
9 8 7 6 5 4 3 2 1 0
We now first compare and then decrement by see 0 in the output.
If we want to first decrement and then compare, use this code:
#include <stdio.h>
int main(void)
{
int x = 10;
while( --x> 0 ) // x goes to 0
{
printf("%d ", x);
}
return 0;
}
That output is:
9 8 7 6 5 4 3 2 1