GCGrowCarrer

Conditionals and Branching

Locked

Lesson 4 of 25 · Syntax · Easy

Finish these first:Operators and Comparisons →Or pass the tests below to unlock it now.

1

The big idea

An if statement lets Rust choose whether to run a block of code. No parentheses are needed around the condition: Notice let mut grade: in Rust, adding mut means "it is okay to change this variable later."

Think of it like this: Think of Rust's `if` like a switch: when the condition is true, Rust runs the lines inside `{ ... }`.
Key words (tap to learn):
2

Read the lesson

An if statement lets Rust choose whether to run a block of code. No parentheses are needed around the condition:

let score = 92;
let mut grade = "";
if score >= 90 {
    grade = "A";
}

Notice let mut grade: in Rust, adding mut means "it is okay to change this variable later."

3

Quick check

Why did we write `let mut status = "";` instead of `let status = "";`?

4

Your challenge

2 sample tests, 1 hidden

Inside main(), write an if check: when age >= 18, set status = "adult";.

Stuck? Get a hint (free)
More learning tools(compare languages, visual guide, related lessons)

Compare with another language

Similar to python.conditionals (92% overlap). Branching control flow: if/else and switch/match expressions.

Visual walkthrough

A diagram, a step-by-step animation, and short captions for Conditionals and Branching.

Mastery0%

Learn this first