Control Flow in Rust

Control flow in Rust gives you the ability to execute code based on a condition. We have a few ways to control the flow of our program in Rust.

Learn Rust by Practice

Master Rust through hands-on coding exercises and real-world examples.

If Expressions

The most basic form of control flow is the if expression along with the else and else if expressions.

Loops

Loops are a way to execute code repeatedly until a certain condition is met. Rust has three kinds of loops: loop, while, and for.

Pattern matching

Rust provides a way to do a more complex form of control flow using pattern matching, you can use match to compare a value against a series of patterns and then execute code based on which pattern matches, or you can use the if let expression to match a single pattern.


In the next lesson we're going to learn about if expressions.