Merge pull request #3889 from rust-lang/chriskrycho/ch-3-break-vs-return

Chapter 3: Clarify `return` vs. `break`.
This commit is contained in:
Chris Krycho 2024-04-17 12:03:43 -06:00 committed by GitHub
commit 7f2149c356
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 0 deletions

View File

@ -250,6 +250,9 @@ and then check whether the `counter` is equal to `10`. When it is, we use the
semicolon to end the statement that assigns the value to `result`. Finally, we
print the value in `result`, which in this case is `20`.
You can also `return` from inside a loop. While `break` only exits the current
loop, `return` always exits the current function.
#### Loop Labels to Disambiguate Between Multiple Loops
If you have loops within loops, `break` and `continue` apply to the innermost