官术网_书友最值得收藏!

The if statements – how to control the code flow

This is how we can branch our code logic based on some data stored in a variable:

let num = 5
if num % 2 == 0 {
print("The number \(num) is even.")
} else {
print("The number \(num) is odd.")
}

The general pattern of an if statement is organized as follows:

var logicalCheck = 7 > 5
if (logicalCheck) {
//code which will be executed if the logical check is evaluated to true
} else {
//code which will be executed if the logical check is evaluated to false
}

We know that the if clause gives us huge freedom to shape the code that will be executed (evaluated). An application may handle many different cases, but only the code that fulfills the conditions encoded in our solution will be triggered.

主站蜘蛛池模板: 许昌市| 凤山市| 涞水县| 温泉县| 武义县| 广州市| 年辖:市辖区| 明光市| 沙洋县| 禹城市| 阿拉善盟| 尉氏县| 漠河县| 武邑县| 太谷县| 定结县| 乐昌市| 扎赉特旗| 嫩江县| 历史| 许昌县| 磴口县| 瓮安县| 获嘉县| 博湖县| 永定县| 吴堡县| 当阳市| 顺平县| 内乡县| 徐水县| 泰和县| 保德县| 新津县| 山阴县| 留坝县| 九江县| 贵阳市| 安达市| 湖南省| 托里县|