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
54
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
83
SQL Intro
nedval
0
100
Featured
See All Featured
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
34
6k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
53
2.9k
Testing 201, or: Great Expectations
jmmastey
45
7.7k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
46
7.6k
Practical Orchestrator
shlominoach
190
11k
Become a Pro
speakerdeck
PRO
29
5.5k
[RailsConf 2023] Rails as a piece of cake
palkan
57
5.8k
Stop Working from a Prison Cell
hatefulcrawdad
271
21k
Build The Right Thing And Hit Your Dates
maggiecrowley
37
2.9k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Six Lessons from altMBA
skipperchong
28
4k
How GitHub (no longer) Works
holman
315
140k
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("不能開冷氣"); }