14.2 Conditional Flow Control
In the previous chapter we looked at how to use logical expressions in Kotlin to determine whether something is true or false. Since programming is largely an exercise in applying logic, much of the art of programming involves writing code that makes decisions based on one or more criteria. Such decisions define which code gets executed and, conversely, which code gets by-passed when the program is executing.
14.2.1 Using the if Expressions
The if expression is perhaps the most basic of flow control options available to the Kotlin programmer. Programmers who are familiar with C, Swift, C++ or Java will immediately be comfortable using Kotlin if statements, although there are some subtle differences.
The basic syntax of the Kotlin if expression is as follows:
if (boolean expression) {
// Kotlin code to be performed when expression evaluates to true
}
Unlike some other programming languages, it is important...