August 2017
Intermediate to advanced
440 pages
10h
English
A range is a way to define a sequence of values. It is denoted by the first and last value in the sequence. We can use ranges to store weights, temperatures, time, and age. A range is defined using double dot notation (under the hood, a range uses the rangeTo operator):
val intRange = 1..4 // 1
val charRange= 'b'..'g' // 2
The Int, Long, and Char type ranges can be used to iterate over next values in the for... each loop:
for (i in 1..5) print(i) // Prints: 1234
for (i in 'b'..'g') print(i) // Prints: bcdefg
Ranges can be used to check ...
Read now
Unlock full access