BeginnerLoops
While Loop
Loop while a condition is true.
kotlin
fun main() {
var count = 1
while (count <= 5) {
println(count)
count++
}
}Output
1
2
3
4
5
Explanation
The while loop checks the condition before each iteration. count++ increments by 1.