Kotlin while Loop

Kotlin , while and do..while work as usual. while and do...while works similar to java while and do..while loop .he while loop is used to iterate a part of program several time. Loop executed the block of code until the condition has true. Kotlin while loop is similar to Java while loop.

  Syntax:

while(condition){  
//body of loop  
} 


Example of while Loop


fun main(array: Array) {


//  Example of while loop
    var i: Int = 1

    while (i < 10) {
        println(i)
        i++
    }


}
1
2
3
4
5
6
7
8
9
woman avatar