Re: [問題] C語言裡的 for(;;)

看板C_and_CPP作者 (研修医当直)時間13年前 (2013/02/22 19:49), 編輯推噓6(602)
留言8則, 7人參與, 最新討論串2/2 (看更多)
※ 引述《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
無限迴圈終止條件如果有需要 兩邊都要是的 但While多一項
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
文章代碼(AID): #1H9rit4F (C_and_CPP)
討論串 (同標題文章)
文章代碼(AID): #1H9rit4F (C_and_CPP)