July 2018
Intermediate to advanced
242 pages
8h 6m
English
We have used a range expression together with the in operator in order to define a condition for the if statement. The condition statement is natural to read and concise. In contrast, an equivalent classic implementation would look like this:
val randomInt = Random(20).nextInt()if (randomInt >= 0 && randomInt <= 10) { print("$randomInt belongs to <0, 10> range")} else { print("$randomInt doesn't belong to <0, 10> range")}
No doubt, the declarative approach using the range and in operator is cleaner and easier to read, compared to classic, imperative-style condition statements.
Read now
Unlock full access