Kotlin provides three different types of ranges: integer, long, and character. Each range can be declared with explicit type declaration:
val myIntRange : IntRange = 1..10
val myLongRange : LongRange = 1..10L
val myCharRange : CharRange = 'a'..'z'
for (ch in myCharRange) {
println(ch)
}
Like other variables, a range can also be declared without explicitly declaring the variable type:
val IntRange = 1..10
val LongRange = 1..10L
val CharRange = 'a'..'z'
for (ch in myCharRange) {
println(ch)
}
While declaring a range of long type, it is necessary to provide the L character with at least one of the elements to differentiate it from the integer type of range.