Archive for May, 2012
Ternary
Another short post. It’s because I’m working on something.
A lot of languages have a ternary operator, that lets you do this:
int x = foo ? 1 : 2;
It’s an easy way to pack a conditional on to one line, especially useful when giving things default values. Another way is if the if
statement returns a value, like in Ruby:
x = if foo 1 else 2 end