How can I take a truth table and turn it into a compacted if block?
For instance, let's say I have this truth table where A and B are conditions and x, y and z are possible actions:
A B | x y z
-------------
0 0 | 0 0 1
0 1 | 0 0 1
1 0 | 0 1 0
1 1 | 1 0 0
This could transform into below if block:
if(A)
{
if(B)
{
do(x)
}
else
{
do(y)
}
}
else
{
do(z)
}
This is an easy sample, but I frequently have several conditions that combined in different ways should produce different outputs and it gets hard to figure out the most compacted and elegant way to represent their logic in an if block.