1. Member
Join Date
Jul 2010
Posts
5
Rep Power
0

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.

2. Java 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.

3. Actually your truth table should look like this:

Java 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

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•