Created
June 8, 2023 11:21
-
-
Save kalaiselvan369/194582f654458e197b4158cd3563160d to your computer and use it in GitHub Desktop.
Ranges
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main() { | |
val numbers = listOf<Int>(1, 2, 3, 4) | |
for(n in numbers) { | |
print(n) | |
} | |
println() | |
for (n in 1..5) { | |
print(n) | |
} | |
println() | |
for (n in 1 until 5) { | |
print(n) | |
} | |
println() | |
for (n in 1..5 step 2) { | |
print(n) | |
} | |
println() | |
for (n in 5 downTo 1) { | |
print(n) | |
} | |
println() | |
modify(10..15) | |
} | |
fun modify(progression: IntProgression) { | |
for(n in progression) { | |
print("$n ") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment