Play With Lua!

Archive for May, 2012

Ternary

without comments

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

Read the rest of this entry »

Written by randrews

May 10th, 2012 at 3:15 pm

Posted in Uncategorized