CPP基礎.Lesson 2
if
, eles if
, else
水獺今天對發票,他心裡想著
如果我中200我要喝一杯珍奶
中500想吃麥當當
中1000萬想要環遊世界
但是因為他很健忘常常忘記
於是他寫下了這個程式
語法教室
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
if
:
true 就會執行{}內的code
else
:
if條件不成立時要做的事(一定要接在if後面)
else if
:
夾在if
和else
中間,用法同if
,但是最多只會執行其中一個{ }
內的程式。通常用在多種情況選一種的時候。
可以使用>
,==
,<
來當作條件
像是a>b
之類的
在程式的世界裡==
是比較兩邊的值一不一樣
=
是把右邊的值複製一份給左邊
兩者不太一樣要注意唷
for
loop
假設今天我們想要印出10行我想躺躺
我們可以這麼做
我好累好累我要天天躺躺水獺Wed, May 19, 2021 8:34 PM
但是如果一次想印100行,總不能永遠的copy paste 吧
所以就發明了loop(迴圈)來幫助我們執行重複的指令~
我們只需將程式寫成這樣
語法教室
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
for
loop
在… 做什麼事
小練習
a244: 新手訓練 ~ for + if
while
loop
水獺抱怨完了
是時候補充能量了!!
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
語法教室
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
while
loop
true 就會執行{ }
內的code
回家作業
d072: 格瑞哥里的煩惱 (Case 版)
c420: Bert的三角形 (3)