Loop Labels
This lesson discusses loop labels in Rust.
We'll cover the following...
What Is a Loop Label?
A loop label assigns an identifier to a loop.
Syntax
Write a label and colon before the loop.
Example
The code below prints the multiplication table of 1 to 5 except 3. See how specifying a loop label helps you to skip the table of 3.
Press + to interact
fn main() {'outer:for i in 1..5 { //outer loopprintln!("Muliplication Table : {}", i);'inner:for j in 1..5 { // inner loopif i == 3 { continue 'outer; } // Continues the loop over `i`.if j == 2 { continue 'inner; } // Continues the loop over `j`.println!("{} * {} = {}", i, j, i * j);}}}