What if the condition is false?

If the condition in an if statement is false, the block of code associated with that condition will not be executed. Instead, if there is an else clause provided, the code within the else block will be executed. If there is no else clause, the program will simply skip the if block and continue with the next part of the code.

Here's a simple example in Rust:

fn main() {
    let number = 7; // Condition will be false
    if number < 5 {
        println!("condition was true");
    } else {
        println!("condition was false"); // This will be executed
    }
}

In this example, since number is 7, the condition number < 5 is false, so the output will be:

condition was false

0 Comments

no data
Be the first to share your comment!