This page topics close

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

    Example)
    drag_handle
     
    fun main(array: Array<String>) {
    
    
    //  Example of while loop
        var i: Int = 1
    
        while (i < 10) {
            println(i)
            i++
        }
    
    
    }
    Output:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    

What next?

The next topic is Kotlin do while Loop

Share this page