Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the proper equivalent of "while(true)" in plain C?

Tags:

c

algorithm

Since C doesn't have bools, 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" ?

like image 803
Microsoft Orange Badge Avatar asked Jun 06 '15 04:06

Microsoft Orange Badge


People also ask

What is while true in C?

A while loop in C programming repeatedly executes a target statement as long as a given condition is true.

How do you say true in C?

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.

Is 1 false or true in C?

Like in C, the integers 0 (false) and 1 (true—in fact any nonzero integer) are used.

What is true in while statement?

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.


1 Answers

Usually nowadays I see

while(1) {
    ...
}

It used to be common to see

for(;;) {
    ...
}

It all gets the point across.

like image 87
U2EF1 Avatar answered Oct 13 '22 23:10

U2EF1