最好使用哪个无限循环 [英] Which infinite loop is preferable to use

查看:111
本文介绍了最好使用哪个无限循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
是";)”比"while(TRUE)"更快?如果没有,人们为什么要使用它?

Possible Duplicate:
Is “for(;;)” faster than “while (TRUE)”? If not, why do people use it?

我正在阅读一本编程书籍(java),在那儿作者使用for(;;)而不是while(true).这个东西真的开始惹恼我,所以我认为我应该检查哪种才是最好的,以及是否有任何区别.这是可能的无限循环:

I been reading a programming book(java) there the author uses for(;;) instead of while(true). This thing realy starts to annoy me so I thought I should check which is the best to use and if there are any diffrences. Here are the possible infinite loops:

for(;;){

}

while(true){

}

do{

}while(true)

  • 哪个更喜欢使用?
  • 性能是否存在差异(例如您必须测试while情况下true是否为真)还是它们被编译为同一事物?
  • 推荐答案

    它们被编译为同一件事,仅是样式问题.较老的程序员可能会认识到for(;;),但我可能只会使用while(true).

    They are compiled to the same thing, and are merely a matter of style. Older programmers may recognize for(;;), but I would probably just use while(true).

    这篇关于最好使用哪个无限循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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