Lesson 2 of 11
Variables and types
Name values, discover their types, and update a mutable variable.
main.rs
fn main() { let mut score: i32 = 3; let bonus = true; score += 2; println!("Score: {score}"); println!("Bonus: {bonus}");}Program state
- Variables
- None
Step 1 of 6
The program starts with no local variables.
What’s happening
A let statement binds a name to a value. Rust can often infer its type from the value you give it. Here i32 means a signed integer and bool means true or false.
Bindings are immutable by default. Use let mut for a variable you plan to update. Assignments to that variable must keep its type.
Read more in The Rust Book