Tsallaka zuwa abun ciki
Justice Tech School

Loop Labels

Labels name loops so break and continue can target an outer loop.

Example
fn main() {
    'outer: for i in 0..3 {
        for j in 0..3 {
            if j == 1 { continue; }
            if i == 2 { break 'outer; }
            println!("{} {}", i, j);
        }
    }
}

Result

0 0
0 2
1 0
1 2

Exercise

Label syntax.

': for

Quiz Test

What does break 'outer do?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.