为什么选择for(;;){} over while(1)? [英] Why choosing for (;;){} over while(1)?

查看:202
本文介绍了为什么选择for(;;){} over 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){}?

推荐答案

它们产生相同的代码。有几个原因为什么你可能更喜欢<; c $ c> for(;;),但它只是个人偏好:

They produce identical code. There are a couple of reasons why you might prefer for (;;) but it is all just personal preference:


  1. 一些编译器会警告你总是正确的条件。 for(;;)不会有这个问题。

for ;;)逐字地读为Just loop forever!,而 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.

这篇关于为什么选择for(;;){} over while(1)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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