I'm new to Rust, and I'm going through the book, I'm at chapter 3.5 - returning values from the loops, where it says:
Then we declare a variable named
resultto hold the value returned from the loop.
Here's a bit of code that confuses me:
break counter * 2;
That's because in previous chapter
x + 1line without a semicolon at the end, which is unlike most of the lines you’ve seen so far. 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. Keep this in mind as you explore function return values and expressions next.
So my question is:
Why is that
break counter * 2; returns a value? It works and compiles with or without a semicolon, by the way.