Possible Duplicate:
Is “for(;;)” faster than “while (TRUE)”? If not, why do people use it?
Why use the ugly for(;;开发者_如何学C)
syntax instead of the slightly better looking while(true)
loop?
There is no advantage to for(;;)
over while(1)
.
Use while(1)
, because it's easier to comprehend (imho). I've never seen a for(;;)
used before, and it may be confusing to others who view your code, and may wonder the same thing you just asked.
EDIT: Here's a link: while (1) Vs. for (;;) Is there a speed difference?
It basically says that they both generate the same code. In assembly, it's jmp ...
.
Less typing? It's shorter. And on a QWERTY keyboard, typing for
alternates between the left and right hand, and while
has three consecutive letters that are typed with the right hand, making typing it potentially even slower.
精彩评论