Rullst AcademyRullst Academy/Lesson
Rust: from idea to program · Lesson 01 / 08

Values that can change

In the Rullst quiz, points change when someone answers correctly. Now let’s look at the language used to write that rule: Rust.

Learning paths8 min

Let's discover together

  1. 1

    A name can hold a value: let energy = 2;. Read it as “the name energy starts with value 2.” The semicolon ends this statement.

  2. 2

    By default, we cannot assign a new value to the same binding. let mut energy = 2; allows changes. mut means mutable; use it when change belongs in the rule.

  3. 3

    energy += 3; adds 3 to the current value. It is short for energy = energy + 3;. The right-hand side is calculated before storing the result.

  4. 4

    fn main() { ... } is this program’s entry point. println! displays a message in the terminal. Here we assemble and predict the snippet; the final project can run on your computer.

✦
YOUR MISSION

Build a small energy update and predict the final value.

Now it's your turn

Discovery workshop

Power up the robot

Starting state: 2 units. The station adds 3. Choose the pieces and predict the printed number.
Your snippet in progress
let {1} energy = 2;
energy {2} 3;
println!("{energy}");
// {3} ?
Build your answers and check when you are ready.
A moment to understand

Why did we add mut?

I need a hint

mut is about allowing value changes, not speed.

Loading your journey…

Take it with you

Predict the result if energy starts at 7 and gains 2. Then ask: does a name that never changes need mut?

Show me the Rust behind it

This part is optional. You don't need to memorize the code to continue.

fn main() {
    let mut energy = 2;
    energy += 3;
    println!("{energy}");
}
At your own pace

My files and GitHub

Every lesson can become your own record: code, notes or a practice plan. Saving a file to GitHub is optional and does not change your XP.

Student guide

The editor and downloads open when this lesson is available to your account. Check access below or return to the track map.

Checking your access to this lesson…

Rullstpetbot

AI can make mistakes. Check the lesson material.