Is quot;for(;;)quot; faster than quot;while (true)quot;? If not, why do people use it?(是“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)?
推荐答案
- 并没有更快.
- 如果您真的很在意,请使用适用于您平台的汇编器输出进行编译,然后看看.
- 没关系.这从来都不重要.随心所欲地编写无限循环.
这篇关于是“for(;;)"比“while(真)"快?如果不是,人们为什么要使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:是“for(;;)"比“while(真)"快?如果不是,人们为什么要使用它?


基础教程推荐
- 这个宏可以转换成函数吗? 2022-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 我有静态或动态 boost 库吗? 2021-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01