Skip to main content

4 docs tagged with "match"

View all tags

`match` Expressions (Part 1): The Basics of Pattern Matching

We've seen how to use if-else and else if to make decisions in our code. However, when you have a long chain of else if statements, it can become clumsy. For more complex conditional logic, Rust has a powerful control flow construct called match. A match expression allows you to compare a value against a series of patterns and then execute code based on which pattern matches.

`match` Expressions (Part 2): Advanced Patterns

In the previous article, we learned the basics of match expressions. Now, we're going to explore some of the more advanced patterns that make match one of Rust's most powerful features. These patterns allow you to write even more expressive and concise conditional code.

Pattern Matching with `match`

We've seen the match expression a few times already, especially when working with enums like Option and Result. In this article, we're going to take a deeper dive into what makes match so powerful: pattern matching.

Project: Guessing Game (Part 2)

In Part 1 of our Guessing Game project, we set up the project and generated a random secret number. Now, it's time to add the core logic of the game: getting the user's guess and comparing it to the secret number.