You could always do:
if ((x > 10) ? (y >5) : (z > 2)) action1
else action2
For completeness sake, any if p then q else r
statement can be expressed logically as (!p && r) || q
. So, we can express the original statement as:
a = x > 10
b = y > 5
c = z > 2
(!a && (!c && action2) || ((!b && action2) || action1))
Which you can expand out as:
(!a && !c && action2) ||
(!a && c && action1) ||
( a && !b && action2) ||
( a && b && action1)
If you collect action1 to one side, you get:
( a && b && action1) ||
(!a && c && action1) ||
( a && !b && action2) ||
(!a && !c && action2)
It really expands to:
( a && b && c && action1) ||
( a && b && !c && action1) ||
(!a && b && c && action1) ||
(!a && !b && c && action1) ||
( a && !b && c && action2) ||
( a && !b && !c && action2) ||
(!a && b && !c && action2) ||
(!a && !b && !c && action2)
And from that we can see we can simplify it to:
( a && b && c && action1) ||
( a && b && !c && action1) ||
(!a && b && c && action1) ||
(!a && !b && c && action1) ||
action2
Since all paths leading to action2 are the negation of any path leading to action1, and we can further reduce it to:
( a && b && action1) ||
(!a && c && action1) ||
action2
Which can itself be reduced to:
((( a && b &&) || (!a && c)) && action1) ||
action2
Which can then be written as:
if ((a && b) || (!a && c)) action1
else action2
Which becomes:
if ((x > 10 && y > 5) || (!(x > 10) && z > 2)) action1
else action2
Which is what we get anyways.