2 ms·
if (condition) { do_x() } else { do_y() } That's the JavaScript version of what you wrote, and it's nearly identical. JavaScript doesn't require line breaks.
by ravenstine 7y ago
if (condition) { do_x() } else { do_y() }
That's the JavaScript version of what you wrote, and it's nearly identical. JavaScript doesn't require line breaks.
- kbp 7y agoThe significant difference is that in Rust, like in Lisp, `if` is an expression, so if-else essentially is the ternary operator. const x = cond1 ? a : cond2 ? b : c becomes in Rust let x = if cond1 { a } else if cond2 { b } else { c }