Name a loop
Place name: before a loop to give it a label. break name exits that loop through any nested loops; continue name advances or retests it.
Labels are local to a function and visible only inside their loop body. They occupy a separate namespace from values and types.
fn main() {
search: for row in [[1, 2], [3, 4]] {
for cell in row {
if cell == 3 {
println("found $cell")
break search
}
}
}
println("done")
}
Examples use the moon toolchain version shown beside each result.
Output & diagnostics
Expected: found 3 done
Ctrl/⌘+Enter runs the current lesson.