In the following snippet, break counter * 2 ending with ; or not, would not affect it returns value 20. It is different from what I find in rust online book, which says expression must not end with ;.
What is more unbelievable is, {} is said to be an expression, it is true in loop but not while, so the last println! throws an error like cannot format which I guess counter is an empty tuple. But I think counter should be integer 0.
fn loop_flow() {
let mut counter = 0;
let a = loop {
counter += 1;
if counter == 10 {
break counter * 2
}
};
println!("value a is {}", a);
let counter = while counter != 0 {
counter -= 1;
counter
}
println!("counter: {} should be 0", counter);
}