Control Flow
While Loop
Repeat while a condition remains true.
While Loop
WhileLoop.kt
fun main() {
val target =
var current = 1
var steps = 0
while (current < target) {
current += 1
steps += 1
}
println("current=$current")
println("steps=$steps")
}
fun main() {
val target =
var current = 1
var steps = 0
while (current < target) {
current += 1
steps += 1
}
println("current=$current")
println("steps=$steps")
}
fun main() {
val target =
var current = 1
var steps = 0
while (current < target) {
current += 1
steps += 1
}
println("current=$current")
println("steps=$steps")
}
loop
A `while` loop checks its condition before each pass through the block.