while
while repeats its body as long as the condition holds. The condition is tested before each iteration, so the body may run zero times.
rux
var i = 0;
while i < 10 {
Print(i);
i += 1;
}Like every condition, a while condition must be a bool and is written without parentheses.
Exiting Early
Use break to leave the loop before the condition becomes false, and continue to skip to the next test:
rux
while true {
let line = ReadLine();
if line == "quit" { break; }
if line == "" { continue; }
Process(line);
}When a loop is meant to run forever until a break, prefer loop over while true — it states the intent directly.
See Also
for/in— when iterating a collection or a counted rangeloop— the clearer form of an unconditional loopbreak/continue— altering loop control flow