I am new to Rust and just started to read the book about the language. Chapter 3.3 (https://doc.rust-lang.org/book/ch03-03-how-functions-work.html) explains the difference between statements and expressions. It states that expressions do not end with a semicolon:
[...] Expressions do not include ending semicolons. If you add a semicolon to the end of an expression, you turn it into a statement, which will then not return a value.
A bit later, in chapter 3.5 (https://doc.rust-lang.org/book/ch03-05-control-flow.html), loops are discussed. The section "Returning Values from Loops" shows that the syntax:
can be used to return values from a loop. This is demonstrated by this line of code:
break counter * 2;
I am confused about the semicolon at the end of this line. According to the quote above, ending a line with a semicolon makes it a statement which does not return a value. So my question is, why does the syntax require a semicolon at this location? Did i misunderstand something?
I tried running the code without the semicolon at the end and it worked as well. But the question about it being there in the first place remains. Isn't that against the rule of what's a statement and what's an expression?