If Let Expression
This lesson teaches the if let expression in Rust
What Is an if let
Expression? #
if let
is a conditional expression that allows pattern matching. The block of code in the construct executes if the pattern in the condition matches with that of scrutinee expression.
Syntax #
The if let
expression begins with an if followed by a let and then a pattern having values enclosed within round brackets. Then an equal to (=
) followed by a scrutinee expression. Then there is a block of code enclosed within braces{}
.Then there is also an optional else block after this.
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy