while let
A while let
loop is a combination of a while
loop and a let
statement. It allows you to execute the loop body only if the pattern matches.
let mut option = Option::Some(0_usize);
// "while `let` destructures `option` into `Some(i)`,
// evaluate the block (`{}`), else `break`
while let Option::Some(i) = option {
if i > 0 {
option = Option::None;
} else {
option = Option::Some(i + 1);
}
}