Ranges
All the conditions that you wrote in the if/else expression for healthStatus branch off the value of an integer, healthPoints.
Some branches use the structural equality operator to check whether healthPoints is equal to a value, and others use multiple comparison operators to check whether healthPoints is within a range of two numbers.
There is a better alternative for the second group: Kotlin provides ranges to represent a linear series of values.
The .. operator, as in in 1..5, signals a range.
A range includes all values from the value on the left of the .. operator to the value on the right, so
1..5 includes 1, 2, 3, 4, and 5.
Ranges can also be a sequence of characters.
You use the in keyword to check whether a value ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access