In this tutorial you will learn about the Rust if Statement and its application with practical example.
Rust if Statement
If statement allows a block of code to be executed only when a specified condition is true. An if statement evaluates a boolean expression followed by one or more statements. The given boolean expression results in a boolean value that can only be either true or false.
Rust If Statement Flow Diagram

swift-if-statement
Syntax:-
1 2 3 |
if condition { // statements } |
Here, Condition is a Boolean expression that results in either True or False, if it results in True then statements inside if body are executed, if it results in False then execution is skipped from if body.
Example:-
1 2 3 4 5 6 7 |
fn main() { let num = 75; println!("W3Adda Rust If Statement"); if num > 50 { println!("Number Greater than 50") } } |
Output:-