Re: [問題] C語言裡的 for(;;)
※ 引述《kg3363 (深藍)》之銘言:
: 抱歉,因為我是個初學者,想請問一下
: for ( ;; )是代表甚麼意思阿??
: 無限迴圈嗎??
: 開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
: 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
: 問題(Question):
: 餵入的資料(Input):
: 預期的正確結果(Expected Output):
: 錯誤結果(Wrong Output):
: 程式碼(Code):(請善用置底文網頁, 記得排版)
: 補充說明(Supplement):
提供c programming: a modern approach裡面Q&A
page.119中有提到
Q: witch form of infinite loop is preferable,
while(1) or for(;;)?
A: C programmer have traditionally preferred for(;;)
for reasons of efficiency; older compilers would often
force program to test the 1 condition each time through
the while loop. With modern compilers, however, there should be no difference
in performance.
簡單說
你用while(1)每次都會去確認1是否為true
用for(;;)就少去這個步驟,執行速度較快。
但現在的compiler會作最佳化,應該不會有差別了。
for(;;){...}為無窮迴圈 會不停執行花括號中的code
K&R (The C programming language)這本書有提到這件事
而這本書的作者就是c語言的作者......
--
║ ║ ╗ ╔═
╠═╣╔╣ ╔╗╚╗
║ ║╚╩ ║║═╝
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.113.241.34
推
02/23 00:10, , 1F
02/23 00:10, 1F
推
02/23 00:17, , 2F
02/23 00:17, 2F
推
02/23 18:50, , 3F
02/23 18:50, 3F
推
02/24 11:27, , 4F
02/24 11:27, 4F
→
02/25 17:00, , 5F
02/25 17:00, 5F
推
02/26 09:52, , 6F
02/26 09:52, 6F
→
02/26 09:52, , 7F
02/26 09:52, 7F
推
02/26 12:00, , 8F
02/26 12:00, 8F
討論串 (同標題文章)