本文介紹了為什么選擇 (;;){} 而不是 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)?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!