I think that the ternary operators just need some practice. They are not that difficult.
Actually if you think it like and if
and else
(and of ourse else if
) it’s not that hard to understand (and becouse is a one line operator allows you to use it as, for example, a function argument. .
Here the same example with if
and else
. As you can see they use a lot more space (both of them can be coded in one single line).
var result:String;
if(value)
{
result = "result if value is true";
}
else
{
result = "result if value is false";
}
var result:String;
if(myInt != 0)
{
if(myInt % 2 == 0)
{
result = "even.";
}
else
{
result = "odd.";
}
}
else
{
result = "zero.";
}
trace("myInt is ", result);