Re: [問題] 請教for loop的判斷條件式
看板C_and_CPP (C/C++)作者uranusjr (←這人是超級笨蛋)時間14年前 (2012/02/26 17:30)推噓2(2推 0噓 1→)留言3則, 2人參與討論串2/2 (看更多)
※ 引述《yenhun (大狗)》之銘言:
: 開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
: Linux
: 程式碼(Code):(請善用置底文網頁, 記得排版)
: 以前看到的for loop大都是一開始初始條件式或增量的地方
: 看到有兩個以上statement , 用逗號隔開
: 但今天看到有個for loop , 是在條件判斷式的地方有兩個statement , 用逗號隔開
: 如下 :
: #define Bfunc(cpu, mask) \
: for ((cpu) = -1; \
: (cpu) = Afunc((cpu), (mask)), \
: (cpu) < 3;)
: 請問像這樣的for loop
: 是(cpu) = Afunc((cpu), (mask))與 (cpu) < 3 同時為真 , 才會往下執行?
: 還是其中一個為真 , 就會往下執行了呢??
: 懇請高手大大解答! 謝謝!
http://en.wikipedia.org/wiki/Comma_operator
In the C and C++ programming languages, the comma operator (represented
by the token ,) is a binary operator that evaluates its first operand and
discards the result, and then evaluates the second operand and returns this
value (and type).
所以 (cpu) = Afunc((cpu), (mask)), (cpu) < 3 總共會做:
1. (cpu) = Afunc((cpu), (mask))
2. 判斷 1. 的值(assignment 述式回傳左值)
3. 判斷 (cpu) < 3 的值
4. 把 2. 的結果丟掉, 回傳 3. 的結果
--
Les grandes et les meilleurs tone from "Zadok the Priest"
Eine grosse stattliche Veranstaltung by F. Handel
THE MAIN EVENT! These are the men
Sie sind die Besten
"Champions League" by Tony Britten THESE ARE THE CHAMPIONS!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.32.81.146
推
02/26 17:41, , 1F
02/26 17:41, 1F
→
02/26 17:42, , 2F
02/26 17:42, 2F
推
02/26 21:36, , 3F
02/26 21:36, 3F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章