break / continue
break and continue alter the flow of a loop:
breakexits the innermost loop immediately.continueskips the rest of the current iteration and moves on — re-evaluating the condition in awhile, or advancing to the next element in afor.
while true {
let input = ReadLine();
if input == "quit" { break; } // leave the loop
if input == "" { continue; } // skip blank lines
Process(input);
}
Targeting an Outer Loop
By default both act on the innermost enclosing loop. To affect an outer loop instead, give that loop a label and name it: break label or continue label (see Labels):
outer: for row in rows {
for cell in row {
if cell == target { break outer; } // exit both loops
}
}
See Also
loop
loop creates an unconditional infinite loop. It runs until a break exits it. Prefer loop over while true — it states the intent directly and cannot be mistaken for a condition that might change.
Overview
A function groups a sequence of statements under a name so it can be invoked repeatedly. Rux supports several kinds of functions, each covered in a dedicated chapter: