While Loop: Endless loops
● Beginner3 min
while true { … } runs until a break inside it stops the loop.
fn main() {
let n = 1
while true {
n *= 2
if n > 100 {
break
}
}
print(n)
}The program ran and printed:
kavach run endless.kav
128Write while true when the place to stop is in the middle of the block, not at its start. The break leaves the loop; the next page shows it in detail.