What does this condition mean in a while loop?
int x;
cin >> x;
while(x) {
...
}
What does this condition mean in a while loop?
int x;
cin >> x;
while(x) {
...
}
int
has an implicit conversion to bool
. Basically 0
converts to false
, all nonzero values convert to true
So more verbosely, your condition would read
while (x != 0)
As @CoryKramer says, when you have a condition which only contains a variable, even if is a char, int, float, etc. the value 0 is considered as false, and any other as true. If you are using pointers is the same: the NULL value is considered as false, and any other direction is considered as true.