是“for(;;)"比“while(真)"快?如果不是,人们为什么要使用它? [英] Is "for(;;)" faster than "while (true)"? If not, why do people use it?

查看:21
本文介绍了是“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. 没关系.这从来都不重要.随心所欲地编写无限循环.

这篇关于是“for(;;)"比“while(真)"快?如果不是,人们为什么要使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆