book icon indicating copy to clipboard operation
book copied to clipboard

Ch03-05 Control flow: Explicitly document if it's valid to break from a loop with return keyword

Open Henkhogan opened this issue 3 years ago • 1 comments

  • [x] I have checked the latest main branch to see if this has already been fixed
  • [x] I have searched existing issues and pull requests for duplicates

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

Description of the problem: the chapter does not tell if

return value;

is equivalent to

break value;

Suggested fix: Since I read the documentation without ever compiling a rust project, I can not tell if they are equivalent or not

Henkhogan avatar Apr 11 '22 17:04 Henkhogan

Hi, thank you! I will clear this up in the text when I'm next working on Chapter 3.

To answer your immediate question, return always goes out of the current function while break only exits the current loop.

carols10cents avatar Apr 11 '22 20:04 carols10cents