- 01Setting up (what you'll need)
- 02Your first output (println!)
- 03Variables and mutability (let / mut)
- 04Type annotations and basic types
- 05Branching (the if statement)
- 06Repeating (the for loop)
- 07Writing your own function
- 08Repeating (while and loop)
- 09Ownership, the basics
- 10Borrowing (references, &)
- 11Working with vectors (Vec)
- 12Structs
- 13enum and the match expression
- 14The Option type (null safety)
- 15The Result type and error handling
- 16Traits
- 17Generics
- 18Closures
- 19Working with strings (String)
- 20[Project] Build a small inventory system
Repeating (while and loop)
This lesson covers the while statement for conditional repetition and the loop statement for infinite loops.
while condition { ... } repeats for as long as the condition is true. loop { ... } repeats unconditionally and is exited explicitly with break.
The sample code shows a while statement that repeats while count is 3 or less.
A common early stumble is choosing between loop and while true. Rust convention says to use loop whenever the infinite loop is deliberate.
In professional work, loop is used for repetition with no clear finishing condition — a server waiting for requests, for example.
๐งช This site can't compile or run Rust directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ nothing is sent anywhere).
