# Decision structure truth table

• 07-13-2010, 08:34 AM
JMaste
Decision structure truth table
Hi,

if (test_1) // condition 1
statement_1;
else if (test_2) // condition 2
statement_2;
else
if (test_3) // condition 3
statement_3;
else
statement_4;

For the structure given above the truth table is given below. I am not able to understand how they came to this truth table. Can you please explain a bit?

Condition 1 Condition 2 Condition 3
----------- ----------- -----------
1) True False False
2) False True False
3) False False True
4) False False False

Thank you.
• 07-13-2010, 10:14 PM
Sno
Code:

```if (test_1) { // Condition 1  (True, False, False, False)     statement_1; } else if (test_2) { // Condition 2 (False, True, False, False)     statement_2; }   else{ // Condition 3 (False, False, True, False)       if (test_3) {           statement_3;       }         else{             statement_4;       } }```
Condition 1 Condition 2 Condition 3
----------- ----------- -----------
1) True False False
2) False True False
3) False False True
4) False False False

I cleaned you your code a bit.

A truth table just tells you what happens to the rest of the IF statements pending on if the IF statement is True or False. The table just lays out the possibilities.
• 07-14-2010, 07:31 AM
JosAH
Actually your truth table should look like this:

Code:

```        Condition 1    Condition 2    Condition 3         -----------    -----------    ----------- 1)        True            d/c            d/c 2)        False            True            d/c 3)        False            False          True 4)        False            False          False```
d/c means "don't care" because if, say, Condition1 is true you don't really care what the other conditions are because the first if-statement is executed.

kind regards,

Jos