可能的重复:
是for(;;)"比while (TRUE)"快?如果不是,人们为什么要使用它?
我看到了
for (;;)
{
// Some code here
}
经常出现.但它提供了什么好处,为什么不选择 while(1){}?
quite often. But what benefits does it offer and why just not choose while(1){}?
它们产生相同的代码.您可能更喜欢 for (;;) 的原因有很多,但这只是个人喜好:
They produce identical code. There are a couple of reasons why you might prefer for (;;) but it is all just personal preference:
有些编译器会警告您有关始终为真的条件.for(;;) 不会有这个问题.
for (;;) 字面意思是永远循环下去!",而 while (true) 仍然出现有某种条件.
for (;;) literally reads as "Just loop forever!", whereas while (true) still appears to have some kind of condition.
我说选择一个并坚持下去.只要不随意切换都无所谓.
I say pick one and stick with it. It doesn't matter as long as you don't switch between them arbitrarily.
这篇关于为什么选择 (;;){} 而不是 while(1)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
编译器如何处理编译时分支?What do compilers do with compile-time branching?(编译器如何处理编译时分支?)
我可以使用 if (pointer) 而不是 if (pointer != NULL) 吗Can I use if (pointer) instead of if (pointer != NULL)?(我可以使用 if (pointer) 而不是 if (pointer != NULL) 吗?)
在 C/C++ 中检查空指针Checking for NULL pointer in C/C++(在 C/C++ 中检查空指针)
比较运算符的数学式链接-如“if((5<j<=1))&quMath-like chaining of the comparison operator - as in, quot;if ( (5lt;jlt;=1) )quot;(比较运算符的数学式链接-如“if((5<j<=1)))
“if constexpr()"之间的区别与“if()"Difference between quot;if constexpr()quot; Vs quot;if()quot;(“if constexpr()之间的区别与“if())
C++,'if' 表达式中的变量声明C++, variable declaration in #39;if#39; expression(C++,if 表达式中的变量声明)