Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

for(;true;) different from while(true)?

Tags:

c++

c

If my understanding is correct, they do exactly the same thing. Why would anyone use for the "for" variant? Is it just taste?

Edit: I suppose I was also thinking of for (;;).

like image 708
Sydius Avatar asked Jan 13 '09 20:01

Sydius


People also ask

What is the difference between while and while true in Python?

While loop is used to execute a block of code repeatedly until given boolean condition evaluated to False. If we write while True then the loop will run forever.

Is while 1 same as while true?

It distinguishes 1 and True in exactly the same way that the + example does. It's emitting a LOAD_GLOBAL (True) for each True , and there's nothing the optimizer can do with a global. So, while distinguishes 1 and True for the exact same reason that + does.

Is while 1 the same as while true in C?

Master C and Embedded C Programming- Learn as you go The while is a loop of C or C++. Using this loop we can check one condition, and the statements inside the loop will be executed while the condition is true. The while(1) or while(any non-zero value) is used for infinite loop. There is no condition for while.

What can I use instead of while true in Java?

while(condition == true) will be true while condition is true . You can make that false by setting condition = false .


1 Answers

for (;;)

is often used to prevent a compiler warning:

while(1)

or

while(true)

usually throws a compiler warning about a conditional expression being constant (at least at the highest warning level).

like image 95
Stefan Avatar answered Oct 10 '22 01:10

Stefan