In this tutorial you will learn about the Rust if else if Statement and its application with practical example.
Rust if else if Statement
In Rust, if..else..if statement allows us add alternative set of test conditions in if..else statement using else-if and single else statements for if condition. In such way if..else..if statement is used to select one among several blocks of code to be executed.
Rust if..else..if Statement Flow Diagram
Syntax:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
if condition1 { // statements } else if condition2 { // statements } . . else if conditionN { // statements } else { // statements } |
Example:-
1 2 3 4 5 6 7 8 9 10 11 12 13 |
fn main() { let a = 10; let b = 10; println!("W3Adda Rust If Else If Statement"); if a > b { println!("a is greater than b") } else if a == b{ println!("a and b are equal") } else { println!("b is greater than a") } } |
Output:-