Skip to content
← All examples

Search in a matrix

Rust Loops

labeled break 'rows

Flowchart (ISO 5807)

YesNoStartInput m, keyfound = falserow in mx in rowx == keyfound = trueAAReturn foundEndFigure 1 — contains

Source code

fn contains(m: &Vec<Vec<i32>>, key: i32) -> bool {
    let mut found = false;
    'rows: for row in m {
        for &x in row {
            if x == key {
                found = true;
                break 'rows;
            }
        }
    }
    found
}