Kotlin While Loop

Chapter: Kotlin Last Updated: 19-11-2017 13:45:29 UTC

Program:

            /* ............... START ............... */
                
fun main(args: Array<String>) {

    var i = 1

    while (i <= 10) {
        println("Value $i")
        ++i
    }

}
                /* ............... END ............... */
        

Output

Value 1
Value 2
Value 3
Value 4
Value 5
Value 6
Value 7
Value 8
Value 9
Value 10

Notes:

  • As like In Java, Kotlin while loop continually executes a block of statements while a particular condition is true.
  • Test expression inside the while loop parenthesis is a Boolean expression.
  • If the test expression is evaluated to true then contents inside the while loop will be executed.
  • Process continues until the test expression is evaluated to false.
  • If the test expression is evaluated to false while will terminate it's execution.
Similar Programs Chapter Last Updated
Kotlin Continue Kotlin 02-03-2018
Kotlin Break Statement Kotlin 27-01-2018
Kotlin For Loop Kotlin 30-11-2017
Kotlin Do While Loop Kotlin 19-11-2017
Kotlin When Statement Kotlin 18-11-2017
Kotlin Nested If Kotlin 18-11-2017
Kotlin If Else If Statement Kotlin 22-09-2018
Kotlin If Statement Kotlin 17-11-2017
Kotlin Print And Println Kotlin 22-09-2018
Kotlin Type Conversion Kotlin 17-11-2017
Kotlin Logical Operators Kotlin 17-11-2017
Kotlin Assignment Operators Kotlin 15-11-2017
Kotlin Arithmetic Operators Kotlin 15-11-2017
Kotlin Data Types Kotlin 12-11-2017
Kotlin Variables Example Kotlin 11-11-2017
Kotlin Comments Example Kotlin 11-11-2017
Kotlin Hello World Kotlin 11-11-2017

1