Answers for "kotlin loop until"

2

while loop in Kotlin

-------------------------------------------------------------------------------------------------------------------------------
(while) -----------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------- 
    "same as in java"
        # var colorarray = arrayOf("Red","Green","Blue","Yellow")
        # var i=0
        # while (i < colorarray.size){
        #     println("Counter $i :: ${colorarray[i]}")
        #     i++
        # }


-------------------------------------------------------------------------------------------------------------------------------
(do while) --------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------- 
    "same as in java"
        # var colorarray = arrayOf("Red","Green","Blue","Yellow")
        # var j=0
        # do {
        #     println("Counter $j :: ${colorarray[j]}")
        #     j++
        # }while (j < colorarray.size)
Posted by: Guest on November-13-2021
3

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)
}
Posted by: Guest on May-10-2020
2

kotlin loop

val school = arrayOf("shark", "salmon", "minnow")
for (element in school) {
    print(element + " ")
}
-> shark salmon minnow

for ((index, element) in school.withIndex()) {
    println("Item at $index is $element\n")
}
-> Item at 0 is shark
Item at 1 is salmon
Item at 2 is minnow
Posted by: Guest on June-16-2020
3

kotlin iterate array

val names = listOf("Anne", "Peter", "Jeff")
for (name in names) {
    println(name)
}
Posted by: Guest on May-17-2020
0

while loop kotlin

for (item in collection) print(item)
Posted by: Guest on March-02-2020
0

kotlin loop until

for (i in 1 until 10) {      
    print(i)
}
Posted by: Guest on October-25-2021

Browse Popular Code Answers by Language