Variables in Rust are, by default, immutable. Immutable variables can be shadowed, but never changed.
You can make a variable mutable with the
mutkeyword in its
Once mutable, you can change the value of a variable with assignment (e.g.,
x = 5;) and mutation operators (e.g.,
x += 2;).
Mutation is almost always necessary to perform iteration.
whileexpression is like an
ifexpression, but continues to evaluate the body as long as the condition remains true.
You can nest loops inside each other to create more powerful loops.
You can use
letto declare variables without assigning, though you probably don’t want to.