Excerpt from Chapter 3.5 of the Rust Book:
we use the
breakkeyword with the valuecounter * 2. After the loop, we use a semicolon to end the statement that assigns the value toresult.
Plus the code snippet:
fn main() {
let mut counter = 0;
let result = loop {
counter += 1;
if counter == 10 {
break counter * 2;
}
};
println!("The result is {}", result);
}
I understand how this works and why the result is 20, but I noticed that if I remove the semicolon on the line that contains the break keyword, the program is equivalent.
Why is the semicolon optional in this case?