是“for(;;)"比“while(真)"快?如果不是,人们为什么要使用它?

for (;;) {
    //Something to be done repeatedly
}

我见过这种东西用得很多,但我觉得它很奇怪......说 while(true) 或类似的东西不是更清楚吗?

I have seen this sort of thing used a lot, but I think it is rather strange... Wouldn't it be much clearer to say while(true), or something along those lines?

我猜(这是许多程序员求助于神秘代码的原因)这会快一点点?

I'm guessing that (as is the reason for many-a-programmer to resort to cryptic code) this is a tiny margin faster?

为什么,它真的值得吗?如果是这样,为什么不这样定义:

Why, and is it really worth it? If so, why not just define it this way:

#define while(true) for(;;)

另见:哪个更快:while(1) 还是 while(2)?

推荐答案

  1. 并没有更快.
  2. 如果您真的很在意,请使用适用于您平台的汇编器输出进行编译,然后看看.
  3. 没关系.这从来都不重要.随心所欲地编写无限循环.

相关文章