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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Nedval
October 18, 2016
0
55
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
84
SQL Intro
nedval
0
100
Featured
See All Featured
Building AI with AI
inesmontani
PRO
1
680
Accessibility Awareness
sabderemane
0
49
Faster Mobile Websites
deanohume
310
31k
How to train your dragon (web standard)
notwaldorf
97
6.5k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
1
120
Designing for humans not robots
tammielis
254
26k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
7.9k
The Power of CSS Pseudo Elements
geoffreycrofte
80
6.1k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
55
Embracing the Ebb and Flow
colly
88
5k
Mind Mapping
helmedeiros
PRO
0
78
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
77
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("不能開冷氣"); }