Javatpoint Logo
Javatpoint Logo

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

Output:

five

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

Output:

three

Next Topic#





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA