while loop

hi,
Can anyone tell me what this loop does, i'm new to C++:
1
2
3
4
while(a)
{
    //some statements
}

i'm interested in "while(a)", i mean I am used to things like while(a == 1), that is some condition. So what does the while(a) thing do?

cheers
Last edited on
While(a)
{
}

is infinite loop , provided a has a definate value

Integral values can be implicitly converted to bool. So that's equivalent to while(a!=0)
Thank you for the explanations! Another thing that I forgot is a statement like this:
1
2
3
4
while ((char *obj = next()))
{
    //some statements;
}

Well, the way I interpreted it was that the condition is always true since char *obj = next() is an assignment, leading to an infinite loop, but the way it was used was like there would be a time when the condition would be false. Any comments!!

cheers.
Well, that is not standard C++ - you can't declare a variable inside an expression like that.
But assuming this code:
1
2
3
4
5
char* obj;
while (obj=next())
{
    //some statements;
}


The loop continues as long as obj doesn't equal zero (i.e. as long next() doesn't return zero).
Conversion to bool works for pointers as well.
Hmm....! Thank you very much!
Topic archived. No new replies allowed.