- Unreal Development Kit Game Programming with UnrealScript:Beginner's Guide
- Rachel Cordone
- 216字
- 2021-08-27 11:59:09
Flow control
We learned about comparisons and logical operators earlier. Now what do we do if we want different things to happen depending on the results of those comparisons? Flow control helps us do exactly that. Let's learn how we can specify what happens under different circumstances.
If else
If/else is the basic flow control statement. Let's look at this sentence:
If it's raining I'll take an umbrella.
Using an if statement, that sentence would be written like this:
if(bRaining) { bUmbrella = true; }
We could also add an else statement to it:
If it's raining I'll take an umbrella, otherwise I'll wear short sleeves.
That would be written like this:
if(bRaining) { bUmbrella = true; } else { bShortSleeves = true; }
We can also use Else If for other conditions.
If it's raining I'll take an umbrella, or if it's cold I'll wear a coat, otherwise I'll wear short sleeves.
We could write that like this:
if(bRaining) { bUmbrella = true; } else if(Temperature < ComfortableTemperature) { bCoat = true; } else { bShortSleeves = true; }
The important thing to remember about else/if is, that only one of these conditions will run. If it's raining and cold, only the bRaining
section of the code will run, not bRaining
and Temperature < ComfortableTemperature
.
- 24小時(shí)學(xué)會(huì)電腦組裝與維護(hù)
- 用“芯”探核:龍芯派開發(fā)實(shí)戰(zhàn)
- Creating Dynamic UI with Android Fragments
- 嵌入式系統(tǒng)設(shè)計(jì)教程
- Mastering Adobe Photoshop Elements
- 基于Apache Kylin構(gòu)建大數(shù)據(jù)分析平臺(tái)
- Building 3D Models with modo 701
- Neural Network Programming with Java(Second Edition)
- Istio服務(wù)網(wǎng)格技術(shù)解析與實(shí)踐
- 單片機(jī)原理及應(yīng)用:基于C51+Proteus仿真
- 計(jì)算機(jī)組成技術(shù)教程
- 嵌入式系統(tǒng)設(shè)計(jì)大學(xué)教程(第2版)
- 施耐德M241/251可編程序控制器應(yīng)用技術(shù)
- Arduino+3D打印創(chuàng)新電子制作2
- Hands-On Embedded Programming with C++17