Why choosing for (;;){} over while(1)?(为什么选择 (;;){} 而不是 while(1)?)
问题描述
可能的重复:
是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)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么选择 (;;){} 而不是 while(1)?
基础教程推荐
- c++ STL设置差异 2022-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 提升 ASIO 流缓冲 2021-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
