Skip to content
Learn Netverks

Lesson

Step 8/36 22% through track

control-flow

Control flow

Last reviewed May 28, 2026 Content v20260528
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
beginner

This lesson

This lesson teaches Control flow: the syntax, APIs, and habits you need before advancing in Rust.

Teams ship Control flow on every Rust codebase—skipping it leaves gaps in debugging and code reviews.

You will apply Control flow in contexts like: Infrastructure CLIs, proxies, game engines, blockchain nodes, and latency-sensitive backends.

Write Rust with fn main(), click Run on server—the dev runner compiles main.rs with rustc and runs the binary; fix borrow errors from stderr (requires Rust toolchain; LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

Rust provides if expressions (not just statements), loop, while, and for. if branches must return the same type when used as an expression.

if as expression

let label = if score >= 60 { "pass" } else { "fail" };

for loops

for item in collection iterates—prefer over manual index loops when possible.

Self-check

  1. Can if produce a value?
  2. Which loop is idiomatic for collections?

loop variants

loop { } runs until break. while and for are sugar over pattern matching in many cases. Infinite loops are explicit—no accidental C-style for(;;) footguns if you name intent.

In interviews, mention that if is an expression—this removes a whole class of “assign inside branch” bugs.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • if expression value?
  • loop vs while?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump