Since C doesn't have bool
s, what is the proper variable to put in place of true
in an algorithm that uses
do
{
// ...
} while(true);
???
Should a proper C programmer do
do
{
// ...
} while(1);
or is there a specific variable reserved to mean "something that is not zero/NULL" ?
A while loop in C programming repeatedly executes a target statement as long as a given condition is true.
Zero is used to represent false, and One is used to represent true. For interpretation, Zero is interpreted as false and anything non-zero is interpreted as true.
Like in C, the integers 0 (false) and 1 (true—in fact any nonzero integer) are used.
The "while true" loop in python runs without any conditions until the break statement executes inside the loop. To run a statement if a python while loop fails, the programmer can implement a python "while" with else loop.
Usually nowadays I see
while(1) {
...
}
It used to be common to see
for(;;) {
...
}
It all gets the point across.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With