mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-03-21 14:46:37 +02:00
Make the "break with label" example more illustrative (#1830)
In the old version, using "break 'outer;" and using "break;" (without the label) produce the same output. This version fixes that to make the example more illustrative. --------- Co-authored-by: Martin Geisler <martin@geisler.net>
This commit is contained in:
parent
8080e2add6
commit
f1e4f300ec
@ -6,17 +6,17 @@ to break out of nested loops:
|
||||
```rust,editable
|
||||
fn main() {
|
||||
let s = [[5, 6, 7], [8, 9, 10], [21, 15, 32]];
|
||||
let mut found = false;
|
||||
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 {
|
||||
found = true;
|
||||
break 'outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
print!("{}", found)
|
||||
print!("elements searched: {elements_searched}");
|
||||
}
|
||||
```
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user