Re: [閒聊] 不使用if的寫法

看板Programming作者 (pziyout)時間12年前 (2013/01/10 03:48), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串13/18 (看更多)
※ 引述《stanwu (stanwu)》之銘言: : Hi 各位大大 : 這應該算是骨灰級的老問題了 : int i = 1; : if ( i == 1 ) : printf ("yes"); : else : printf ("no"); : PS: 可彈性調整 i 裡面的值 0-65535 : 如果改寫成 完全拋棄不使用 if 或是 ? : 之類的判斷式, 有其他寫法可以得到一樣的結果嗎? : 任何語言都可以, 感謝各位大大 ^O^ ( i == 1 || cout << "no\n" && 0 ) && cout << "yes\n" ; 利用 short-circuit operator 的特性 A || B --> if ( !A ) B A && B --> if ( A ) B -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.115.25.21 ※ 編輯: pziyout 來自: 140.115.25.21 (01/10 13:55)

01/11 00:45, , 1F
01/11 00:45, 1F
文章代碼(AID): #1GxZeOMz (Programming)
討論串 (同標題文章)
文章代碼(AID): #1GxZeOMz (Programming)