Concise control flow with if let
The if let syntax is used to combine if and let which handles the values that matches one of the patterns while ignoring the rest of the code. The working of “match” operator and “if let” expression is similar.
Example of match operator
In the above example, the match operator executes the code when the value is equal to Some(5). The “_=>()” expression satisfies the match expression after executing the first variant. If we use if let instead of match, then it reduces the length of the code.
Example of if let