Match Expression

This lesson discusses match statements in Rust!

What Is a match Expression? #

Match expression checks if the current value corresponds to any value within the list of values.

Match expression are similar to switch statement in languages like C and C++. They give a more compact code when compared with the if/else construct.

Syntax #

Match expression uses a match keyword.

The match expression can be written in two different ways, which are given below:

Method 1: #

If you do not want to assign a value to the result variable from within the match block

Create a free account to access the full course.

Continue your learning journey with a 14-day free trial.

By signing up, you agree to Educative's Terms of Service and Privacy Policy