Rust - If let Operator Last Updated : 15 Nov, 2021 Comments Improve Suggest changes Like Article Like Report The basic difference between conventional if-else and if let is that if let uses one pattern that needs to be matched to an expression also known as scrutinee, if the pattern matches the expression then the corresponding code is executed, or in most cases that value is assigned according to it. Syntax : let gfg=value; let gfg_answer=if let value_1 = expression{ } else if let value_2=expression{ } ... else{ } Example 1: Program for if let operator in Rust. In this example the value we will have one variable gfg="algo" and we will check it against other values.For the first condition here if the string "cp" equals to gfg variable then gfg_answer will be assigned the value "dsa topic=cp" because we used the concat method to add "dsa topic=" and "cp".let gfg_answer=if let "cp" = gfg { concat!("dsa topic=","cp") } If this condition is not met then it will check for other else if or else conditions.The final step is to print the value of gfg_answer. Rust // Rust program for if let operator fn main() { // string created algo assigned to gfg let gfg = "algo"; // using if let operator let gfg_answer = if let "cp" = gfg { concat!("dsa topic=","cp") } else if let "ds" = gfg { concat!("dsa topic=","ds") } else if let "algo" = gfg { concat!("dsa topic=","algo") } else { concat!("dsa topic=","not in gfg") }; // printing the gfg_answer variable println!("{}",gfg_answer); } Output : dsa topic=algo Example 2 : Here we will use gfg variable having value 10, and we will compare it to values and assign the variable gfg_answer according to it.let gfg = Some(10); let gfg_answer = if let Some(10) = gfg { 11 }And we will keep on checking the conditions until some condition is matched or last will be the else condition.Finally, we will print the gfg_answer variable. Below is the program for if let operator Rust. Rust // Rust program for if let operator fn main() { // gfg variable assigned value 10 let gfg = Some(10); // using if let operator let gfg_answer = if let Some(10) = gfg { 11 } else if Some(20) == gfg { 22 } else if let Some(30) = gfg { 33 } else { -1 }; // printing the value println!("gfg_anser={}",gfg_answer ); } Output : gfg_answer=11 Comment More infoAdvertise with us R rajatagrawal5 Follow Improve Article Tags : Rust Similar Reads Rust - Match Operator Match Operator is a powerful operator which lets you match a particular value with a range of values and execute some operations or code for it. It is similar to switch() in Java. Match Operator Keypoints :For checking for a group of values, where the value to be checked is "cp".Syntax : let gfg = S 3 min read Rust - Operators Operators in general are used to perform operations on values and variables. These are standard symbols used for the purpose of logical and arithmetic operations. In this article, we will look into different types of Rust operators. Operators tell the compiler or interpreter to perform a specific ma 9 min read Rust - Iterator Trait Rust is a systems programming language focusing on speed, concurrency, and ensuring safe code. The iterator trait in Rust is used to iterate over Rust collections like arrays. Syntax: //pub refers to the trait being declared public pub trait Iterator { // type refers to the elements type over which 3 min read Loops in Rust A loop is a programming structure that repeats a sequence of instructions until a specific condition is satisfied. Similar to other programming languages, Rust also has two types of loops: Indefinite Loop: While loop and LoopDefinite Loops: For loopLet's explore them in detail. While LoopA simple wa 3 min read Rust - Literals A literal is a source code that represents a fixed value and can be represented in the code without the need for computation. The compiler uses by default i32 for integers and f64 for float types/. In Rust, literals are described by adding them in the type as a suffix. Example:  Integer literal 6 h 1 min read Rust - if let Statement If-let statement in Rust is an expression that allows pattern matching and is similar to an if expression.  Once the pattern condition is matched then the block of code is executed. A scrutinee is an expression that is matched during match statement executions. For example match g{ X =>5 , Y = 2 min read Like