kotlin loop
for (i in 1..5) print(i)
-> 12345
for (i in 5 downTo 1) print(i)
-> 54321
for (i in 3..6 step 2) print(i)
-> 35
for (i in 'd'..'g') print (i)
-> defg
kotlin loop
for (i in 1..5) print(i)
-> 12345
for (i in 5 downTo 1) print(i)
-> 54321
for (i in 3..6 step 2) print(i)
-> 35
for (i in 'd'..'g') print (i)
-> defg
loops in kotlin
-------------------------------------------------------------------------------------------------------------------------------
(for) -------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------
"for each"
# var colorarray = arrayOf("Red","Green","Blue","Yellow")
# for (i in colorarray){
# println(i)
# }
# for (i in colorarray.indices){
# println(colorarray[i])
# }
"range"
# for (i in 0..10){
# println(i)
# }
"range with keywoard"
# for (i in 0.rangeTo(10).step(3)){
# println(i)
# }
"step"
# for (i in 0..10 step 2){
# println(i)
# }
"down to"
# for (i in 10 downTo 0){
# println(i)
# }
"down to with keywoard"
# for (i in 10.downTo(0).step(3)){
# println(i)
# }
"until"
- do not use last value here it will print only 0-9
# for (i in 0 until 10){
# println(i)
# }
# for (i in 0 until colorarray.size){
# println(colorarray[i])
# }
for loop kotlin
val array = arrayOf(1, 3, 9)
for (item in array) {
//loops items
}
for (index in 0..array.size - 1) {
//loops all indices
}
for (index in 0 untill array.size) {
//loops all indices
}
for (index in array.indices) {
//loops all indices (performs just as well as two examples above)
}
kotlin for loop
val nums = arrayOf(1, 5, 10, 15, 20)
for (x
in nums) {
println(x)
}
how to do a for loop loop kotlin
//This is how you do a for loop in Kotlin
fun main() {
for (i in 1..5) {
println(i)
}
}
//It will print
1
2
3
4
5
//have fun trying kotlin! You will get it hopefully very quickly!
//If your try copying and pasting the code put it in this function! Hopefully it will work!
fun main(args: Array<String>) {
println("Hello Bob")
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us