If..Else

Branch on a condition.

if / else

Run one block when the condition is true, otherwise the other.

fn main() {
    let score = 75
    if score >= 60 {
        print("Pass")
    } else {
        print("Fail")
    }
}

Output

Pass

if as expression

if can return a value directly.

fn main() {
    let score = 95
    let label = if score >= 90 { "A" } else { "B" }
    print(label)
}

Output

A