you are viewing a single comment's thread
view the rest of the comments
[–] 3 points 11 months 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
}
  • source
  • parent