5 ms·
"Why have both an if-statement and a ternary operator?" Because one is for control of statement execution and one is an expression that returns a value. Two si
by mjcohenw 14y ago
"Why have both an if-statement and a ternary operator?"
Because one is for control of statement execution and one is an expression that returns a value. Two similar-in-purpose but different-in-meaning constructs.
In my experience, if the ?-: operator is written in the same way as the if-else (condition, true, and false parts each on their own line), nested expressions are quite clear and understandable.