From f1e4f300ec0dcb8313fe643574b59c6a903aea7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marja=20H=C3=B6ltt=C3=A4?= Date: Tue, 20 Feb 2024 11:06:29 +0100 Subject: [PATCH] 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 --- src/control-flow-basics/break-continue/labels.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/control-flow-basics/break-continue/labels.md b/src/control-flow-basics/break-continue/labels.md index af198c4e..27dbdd81 100644 --- a/src/control-flow-basics/break-continue/labels.md +++ b/src/control-flow-basics/break-continue/labels.md @@ -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}"); } ```