A while loop continues as long as the condition is true.
True is not false. False is 0. Therefore, any non-zero value is true.
Functions that return a value become an instance of their return type. That is,
-
int MyFunction();
-
-
int result = MyFunction(); //return used to intialize result
-
-
So, by calling MyFunction you can use result in your while loop:
and you will stay in the loop as long as result is not zero.
Alternatively, you could code this loop to be:
because result is true if it is not zero.
Alternatively, you can skip using result since it's not required to be an actual variable and recode the while loop to be:
Nothing new happens here. MyFunction() is still called. But the return is put into a temporary int created by the compiler. That int is then tested by the while loop.
In summary, there are not different kinds of while loops. There are different ways of stating whether an expression is true. The loop merely evaluates the expression.