Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
if else statement
Search
Nedval
October 18, 2016
0
49
if else statement
Nedval
October 18, 2016
Tweet
Share
More Decks by Nedval
See All by Nedval
C 程式語言 I
nedval
0
110
軟體測試與驗證—CI & CU
nedval
0
76
SQL Intro
nedval
0
93
Featured
See All Featured
Adopting Sorbet at Scale
ufuk
69
8.6k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
352
28k
Thoughts on Productivity
jonyablonski
60
3.9k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
7
3.4k
Designing Experiences People Love
moore
136
23k
Typedesign – Prime Four
hannesfritz
36
2.1k
We Have a Design System, Now What?
morganepeng
43
6.8k
How GitHub Uses GitHub to Build GitHub
holman
468
290k
Fashionably flexible responsive web design (full day workshop)
malarkey
398
65k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
228
16k
YesSQL, Process and Tooling at Scale
rocio
165
13k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
245
20k
Transcript
IF ELSE STATEMENT by
[email protected]
if ( 邏輯運算式 ) { /* 運算結果為真(條件成立)時, 須執行的程式 */ }
在這之前,需要先認識一個東西 …
None
杯緣子
運算子 + - * / (operator )
算術運算子 + - * /
杯緣子的好朋友叫做 …
杯緣子的好朋友叫做 杯緣
運算子的好朋友叫做 …
運算子的好朋友叫做 運算元(operand)
int e7; e7 = 8 + 9;
int e7; e7 = 8 + 9; 運算子(operator)
int e7; e7 = 8 + 9; 運算元(operand)
if 條件陳述中常用的運算子 && 而且 || 或者 == 等於 != 不等於
<= 小於等於 >= 大於等於 < 小於 > 大於
if 條件陳述中常用的運算子 邏輯 && 而且 || 或者 == 等於 !=
不等於 <= 小於等於 >= 大於等於 < 小於 > 大於
if 條件陳述中常用的運算子 邏輯 && 而且 || 或者 == 等於 !=
不等於 <= 小於等於 >= 大於等於 < 小於 > 大於 個人偏好在程式中 只使用 <= 和 < 不使用 >= 和 > 因為寫起來的順序 與數線相同 較容易閱讀
0 <= < 右大 左小
練習將文字說明改成程式碼
如果氣溫超過 26 度 C,則可以開冷氣,否則不能開。
如果氣溫超過 26 度 C,則可以開冷氣,否則不能開。 if
如果氣溫超過 26 度 C,則可以開冷氣,否則不能開。 26 < temperature
如果氣溫超過 26 度 C,則可以開冷氣,否則不能開。 26 < temperature 邏輯運算子
如果氣溫超過 26 度 C,則可以開冷氣,否則不能開。 26 < temperature 運算元 運算元
if (26 < temperature ) { } 邏輯運算式
如果氣溫超過 26 度 C,則可以開冷氣,否則不能開。 條件成立的結果
if (26 < temperature ) { printf("可以開冷氣"); }
如果氣溫超過 26 度 C,則可以開冷氣,否則不能開。
if (26 < temperature ) { printf("可以開冷氣"); } else {
}
如果氣溫超過 26 度 C,則可以開冷氣,否則不能開。 條件不成立的結果
if (26 < temperature ) { printf("可以開冷氣"); } else {
printf("不能開冷氣"); }
int temperature; printf("請輸入現在溫度(°C): "); scanf("%d", &temperature); if (26 < temperature
) { printf("可以開冷氣"); } else { printf("不能開冷氣"); }
//宣告一個名字為 temperature 的空間用來存放溫度的值 int temperature; //提示使用者輸入溫度 printf("請輸入現在溫度(°C): "); //讀取使用者輸入的溫度並存放到 temperature
的空間 scanf(“%d”, &temperature); if (26 < temperature ) { // 若溫度大於 26 度則顯示可以開冷氣 printf(“可以開冷氣”); } else { // 若溫度沒有大於 26 度則顯示不能開冷氣 printf("不能開冷氣"); }