break_if

Macro break_if 

Source
macro_rules! break_if {
    ($predicate:expr $(,)?) => { ... };
    ($predicate:expr, $label:tt $(,)?) => { ... };
}
Expand description

break from a loop if a given predicate evaluates to true.

Supports optionally providing a loop label to specify the loop from which to break.

§Usage

break_if!(predicate)

break_if!(predicate, label)

§Examples

§Predicate only
use flow_control::break_if;

let mut v = Vec::new();
for outer_n in 1..3 {
    for inner_n in 1..5 {
        break_if!(inner_n == 3);
        v.push((outer_n, inner_n));
    }
}

assert_eq!(
    v,
    vec![
        (1, 1), (1, 2),
        (2, 1), (2, 2),
    ]
);
§Predicate and label
use flow_control::break_if;

let mut v = Vec::new();
'outer: for outer_n in 1..3 {
    for inner_n in 1..5 {
        break_if!(inner_n == 3, 'outer);
        v.push((outer_n, inner_n));
    }
}

assert_eq!(
    v,
    vec![(1, 1), (1, 2)],
);