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.