• calcopiritus@lemmy.world
    link
    fedilink
    arrow-up
    3
    ·
    22 hours ago

    Because it can be done for multiple lines too. And you can do else-if too. Also, “if” and “else” is more recognizable than “?” and “:”

    x = if y > 5 {
        println!("Y was over 5");
        z + 5
    } else if y < 0 {
        handle_negative_y(y);
        z - y
    } else {
        println!("<WARN> unexpected value for y"}
        0
    }