开发者

why for(;;) instead of while(1)? [duplicate]

开发者 https://www.devze.com 2023-01-14 06:32 出处:网络
This question already has answers here: Closed 12 years ago. Possible Duplicate: Is “for(;;)”faster than “while (TRUE)”? If not, why do people use it?
This question already has answers here: Closed 12 years ago.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消