IS"对于(;;)QUOT;而(TRUE)"?;比&QUOT快如果不是,为什么人们使用它? [英] Is "for(;;)" faster than "while (TRUE)"? If not, why do people use it?

查看:182
本文介绍了IS"对于(;;)QUOT;而(TRUE)"?;比&QUOT快如果不是,为什么人们使用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 为(;;){
    //事情要重复执行
}

我已经看到了这种用了很多事情,但我认为这是比较奇怪...
那岂不是更清楚地说,而(真),或沿着这些线路的东西吗?

我猜测,(因为是许多-A-程序员求助于神秘的code的原因),这是一个很小的保证金快?

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

 的#define,而(真)为(;;)

另请参阅:这是更快:在(1)或者同时(2)?


解决方案

  1. 这是不是更快。

  2. 如果你真的关心,编译汇编输出平台,并期待看到的。

  3. 没关系。这从来没有重要的。写下您的无限循环,只要你喜欢。

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

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(;;)

See also: Which is faster: while(1) or while(2)?

解决方案

  1. It's not faster.
  2. If you really care, compile with assembler output for your platform and look to see.
  3. It doesn't matter. This never matters. Write your infinite loops however you like.

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

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