while(true) 与 for(;;)
可能的重复:
是“for(;; )”比“while (TRUE)”更快?如果没有,人们为什么要使用它?
for ( ; ; ) 或 while ( true ) - 哪个是正确的 C# 无限循环?
while(true)
(或 while(1)
)和 for( ;;)
?有什么理由选择其中之一而不是另一个?
Possible Duplicates:
Is “for(;;)” faster than “while (TRUE)”? If not, why do people use it?
for ( ; ; ) or while ( true ) - Which is the Correct C# Infinite Loop?
Is there any appreciable difference between while(true)
(or while(1)
) and for(;;)
? Would there be any reason to choose one over the other?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
启用优化后,它们将进行相同的编译。
您应该使用您认为更具可读性的任何一个。
With optimizations enabled, they will compile identically.
You should use whichever one you find more readable.
不,我认为
for(;;)
看起来更好。但它们是一样的。另请参阅 是“for( ;;)”比“while (TRUE)”更快?如果没有,人们为什么要使用它?
No. I think
for(;;)
looks nicer. But they're the same.Also see Is "for(;;)" faster than "while (TRUE)"? If not, why do people use it?