Rust - While let Statement Last Updated : 08 Sep, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report A Rust While let Statement in Rust is a special statement that basically refractors and allows us to view a clean code. While let statement was inspired by the if let statement in Rust. Basically in an, if let statement, there is a pattern match and then the block of code gets executed. if let Some(n) = option { does_something(n);} This statement is equivalent to: match option { Some(x) => does_something(n), _ => {},} While let is also similar to the above example. In Rust, if we write a pattern match and loop, the expression looks like this: Example 1: Rust fn main() { //gfg -> variable let mut gfg = "Printing GeeksforGeeks without using while let".chars(); loop { match gfg.next() { Some(x) => print!("{}", x), _ => break, } } println!(""); } Output: Now, using the while let statement in Rust. Using while let makes this code easier to read. Example 2: Rust fn main() { //gfg is a variable let mut gfg = "Printing GeeksforGeeks using while let".chars(); while let Some(x) = gfg.next() { //print is a statement that is used to print characters in one line print!("{}",x); } println!("\n"); } Output: Comment More infoAdvertise with us Next Article Rust - if let Statement S sayanc170 Follow Improve Article Tags : Rust rust-control-flow Similar Reads 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 Rust - If-else Statement Branching with if-else in rust also is similar to other languages. Just the difference is the way of writing(syntax). Here the condition doesn't need to be surrounded by parenthesis. Decision-making structure is an important part of life. Similarly, in programming also there are situations where you 3 min read Rust - While Loop Loops in Rust come into use when we need to repeatedly execute a block of statements. Loops are also useful when we need to iterate over a collection of items. In Rust, we have various kinds of loops, including loops, while loops, and for loops. The while loop is the most common loop in Rust. The lo 3 min read Swift - Break Statement The break statement is a loop control statement that is used to end the execution of an entire control flow statement immediately when it is encountered. When the break condition is true, the loop stops its iterations, and control returns immediately from the loop to the first statement after the lo 6 min read Swift - Guard Statement Swift provides a special type of statement referred to as "guard" statement. A guard statement is capable to transfer the flow of control of a program if a certain condition(s) aren't met within the program. Or we can say, if a condition expression evaluates true, then the body of the guard statemen 15 min read Swift - Control Statements in Loops Control statements are used to control the flow of the loop. For example, we have written a for loop, inside the for loop we have written some 3 or 4 if conditions. Consider after satisfying 1st if condition the loop need to break, which means other of conditions should not be executed. In that case 5 min read Like