comparison of an unsigned variable to 0
- by user2651062
When I execute the following loop :
unsigned m;
for( m = 10; m >= 0; --m ){
printf("%d\n",m);
}
the loop doesn't stop at m==0, it keeps executing interminably, so I thought that reason was that an unsigned cannot be compared to 0. But when I did the following test
unsigned m=9;
if(m >= 0)
printf("m is positive\n");
else
printf("m is negative\n");
I got this result:
m is positive
which means that the unsigned variable m was successfully compared to 0.
Why doesn't the comparison of m to 0 work in the for loop and works fine elsewhere?