Basic Labeling - Rust

fn main() {
    let s = [
    [5, 6, 7],
    [8, 9, 10],
    [21, 15, 32]
    ];
    let mut elements_searched = 0;
    let target_value = 10;
    'outer: for i in 0..=2 {
        for j in 0..=2 {
            elements_searched += 1;
            if s[i][j] == target_value {
                break 'outer;
            }
        }
    }
    println!("Elementos pesquisados: {elements_searched}");
}

(Playground)

Output:

Elementos pesquisados: 6

Errors:

   Compiling playground v0.0.1 (/playground)
    Finished `release` profile [optimized] target(s) in 0.47s
     Running `target/release/playground`

I don't know what the exact policy is but for me even a mini-tutorial could be OK if it explains something, preferably something not found in the standard documentation.

As it is your post is just some code pasted in a forum, not very useful. Maybe if you explain what you wanted to do with such a "tutorial" experienced people could suggest ways to do better in the future.

3 Likes