The Ternary If-Statement ("The ? if-statement")

Ternary means "composed of three parts"

booleanCondition ? returnsThisIfBooleanConditionTrue : returnsThisIfBooleanConditionIsFalse;

The first clause is the boolean condition. If that boolean condition is true, the second clause is returned of this entire expression. If it's false, the third clause is returned.

It's kind of like saying this (where a is a boolean expression):

a ? b : c

Is the same as this:

if (a) {
    return b;
} else {
    return c;

So let's set that to a variable:

x = a ? b : c;  

That can be broken down into 2 cases:

if (a) {
    x = b;
else {
    x = c;

Look at some examples (in Java, but it's the same general concept):

boolean foo = true;

System.out.println( foo ? "foo is true!" : "foo is false!" ); // prints "foo is true!"
String foo = "foo";
String bar = "bar";

String fooBar = foo.equals(bar) ? foo : foo + bar;

System.out.println(fooBar); // prints "foobar"

           Created: March 12, 2014
Completed in full by: Michael Yaworski