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
Thoughts on Productivity
jonyablonski
69
4.7k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
26k
Why Our Code Smells
bkeepers
PRO
336
57k
Being A Developer After 40
akosma
90
590k
A Modern Web Designer's Workflow
chriscoyier
695
190k
The Art of Programming - Codeland 2020
erikaheidi
54
13k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
48
2.9k
Balancing Empowerment & Direction
lara
1
440
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
7
740
How GitHub (no longer) Works
holman
314
140k
StorybookのUI Testing Handbookを読んだ
zakiyama
30
5.9k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
161
15k
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("不能開冷氣"); }