Possible Duplicate:
while (1) Vs. for (;;) Is there a speed difference?
Hi,
Which is better,faster and more optimized way to implement infinite loop – for(;;) or while(1)? and why?
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.
In any normal compiler, there should be absolutely no difference. For example, here’s what
LLVM-clanggenerates (with the-O3flag) forwhile (1) {}:Note the
jmp .LBB0_1part, which is the actual infinite loop. For thefor (;;)kind, it generates absolutely the same code.You can also try with other compilers for fun, but it’s best just stop worrying about it.
OK, I just had to try with
gccas well: