🦀

Rust Intermediate

Conditionals, accumulation and iterating over ranges.

3 lessons 5 tasks ⚡ Live compiler
Lessons Compiler Quiz Certificate

📚 Lessons

1 Conditionals

Rust's if/else is an expression. Combine tests with && and ||.

fn main() {
    for n in 1..=6 {
        if n % 2 == 0 {
            println!("{} even", n);
        } else {
            println!("{} odd", n);
        }
    }
}

2 Accumulating values

Use a mut accumulator and a loop to fold a range into a single result.

fn main() {
    let mut product = 1;
    for i in 1..=6 {
        product *= i;
    }
    println!("6! = {}", product);
}

3 While loops

while repeats until its condition is false — handy when the count is data-dependent.

fn main() {
    let mut n = 27;
    let mut steps = 0;
    while n > 1 {
        if n % 2 == 0 { n = n / 2; } else { n = 3 * n + 1; }
        steps += 1;
    }
    println!("steps = {}", steps);
}

⚡ Rust Compiler

Code runs on a learning-oriented simulated runtime that supports common constructs (output, variables, arithmetic, conditionals and loops).

RUST

            

📝 Tasks

5 tasks across 2 pages — multiple-choice and fill-in (type the answer). Score 70% or higher to earn your certificate.

🎓 Certificate of Completion

🔒 Pass the quiz above (70%+) to unlock your downloadable certificate.