rust-lang / book

The Rust Programming Language

Home Page:https://doc.rust-lang.org/book/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

No example for returning a value from labeled loops

CoolCat467 opened this issue · comments

  • I have searched open and closed issues and pull requests for duplicates, using these search terms:
    • "Return a value from labeled loops"
  • I have checked the latest main branch to see if this has already been fixed, in this file:
    • src/ch03-05-control-flow.md

URL to the section(s) of the book with this problem:
https://github.com/rust-lang/book/blob/main/src/ch03-05-control-flow.md
https://doc.rust-lang.org/book/ch03-05-control-flow.html

Description of the problem:
There is nothing mentioned about how you return (loop break) a value from a loop you are breaking that has a label.

Suggested fix:
Add example on how you return (loop break) a value from a labeled loop, as the page describes both loop break returning a value and breaking from a loop with a label, and it's not immediately obvious how you both break from a labeled loop and return a value from the loop scope at the same time.

People on StackOverflow asking about this same issue:
https://stackoverflow.com/questions/72927882/return-a-value-from-labeled-loops