I'm new to rust and like what I've seen so far. I'm checking out the tour and discovered that a common programming pattern I use to define default values in procedural languages is tossing up a warning. My question is why is this and what is the better way to solve the same problem? ( Hopefully with less code not more! )
The pattern is very simple. On function entry assign a default value to some variable, then in the body allow various conditions to change it. Once function ends, if no conditions were triggered then the default value prevails.
In rust (the tour at least), using such a pattern tossing a warning:
warning: value assigned to `v` is never read
`#[warn(unused_assignments)]` on by default
Below is the example from the tour that I modified that displays this warning.
Any advise on this would be most appreciated.
Thanks!
fn main() {
let mut x = 0;
let mut v = "sorry charlie";
v = loop {
x += 1;
if x == 13 {
break "found the 13";
}
if x == 14 {
break;
}
};
println!("from loop: {}", v);
}