Looks like JavaScript, feels like Ruby, and it is a script language fitting in C programmers.
This project is maintained by Kray-G
Ternary operator is a simple if-else
.
a ? b : c
means, if a is true, then b, otherwise c.
var b = a ? 10 : 20;
This expression is evaluated right to left.
function test(a) {
return a ? 10 : 20;
}
System.println(test(true));
System.println(test(False)); // False object.
10
20
function test(b1, b2, b3) {
return b1 ? b2 ? 1 : 2 : b3 ? 3 : 4;
}
System.println(test(0, 0, 0));
System.println(test(0, 0, 1));
System.println(test(0, 1, 0));
System.println(test(0, 1, 1));
System.println(test(1, 0, 0));
System.println(test(1, 0, 1));
System.println(test(1, 1, 0));
System.println(test(1, 1, 1));
4
3
4
3
2
2
1
1