0
0
Rustprogramming~15 mins

Mutable variables in Rust - Mini Project: Build & Apply

Choose your learning style9 modes available
Mutable variables
๐Ÿ“– Scenario: Imagine you are keeping track of the number of apples in a basket. Sometimes apples are added or taken away. You want to write a program that can change the number of apples as needed.
๐ŸŽฏ Goal: You will create a mutable variable to hold the number of apples, change its value, and then print the final count.
๐Ÿ“‹ What You'll Learn
Create a mutable variable called apples with the initial value 5.
Change the value of apples to 10.
Print the value of apples.
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Mutable variables let programs keep track of changing information, like counting items or updating scores.
๐Ÿ’ผ Career
Understanding mutable variables is essential for writing programs that handle data that changes over time, a common task in software development.
Progress0 / 4 steps
1
Create a mutable variable
Create a mutable variable called apples and set it to 5.
Rust
Need a hint?

Use let mut to create a variable that can change.

2
Change the variable value
Change the value of the mutable variable apples to 10.
Rust
Need a hint?

Assign a new value to apples without using let.

3
Print the variable
Print the value of the variable apples using println!.
Rust
Need a hint?

Use println!("{}", apples); to show the value.

4
Run and see the output
Run the program to see the final number of apples printed.
Rust
Need a hint?

The program should print 10 because that is the final value of apples.