In this tutorial you will learn about the Rust Nested If else statement and its application with practical example.
Rust Nested If else statement
In Rust, when there is an if statement inside another if statement then it is known as nested if else. Nested if else can also be simplified using Swift Switch Statement.
Syntax:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
if condition1 { if condition2 { // statements } else { // statements } } else { if condition3 { // statements } else { // statements } } |
Example:-
1 2 3 4 5 6 7 8 9 10 11 12 13 |
fn main() { let a = 25; println!("W3Adda Rust Nested If Statement"); if a < 100 { if a < 50 { println!("a is less than 50") } if a >= 50 { println!("a is greater than 50") } } } |
When we run the above rust program, will see following output –
Output:-