Possible Duplicate:
Is “for(;;)” faster than “while (TRUE)”? If not, why do people use it?
I see this
for (;;)
{
// Some code here
}
quite often. But what benefits does it offer and why just not choose while(1){}?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
They produce identical code. There are a couple of reasons why you might prefer
for (;;)but it is all just personal preference:Some compilers will warn you about conditions that are always true.
for(;;)will not have that problem.for (;;)literally reads as “Just loop forever!”, whereaswhile (true)still appears to have some kind of condition.I say pick one and stick with it. It doesn’t matter as long as you don’t switch between them arbitrarily.