End of Lesson
End of Lesson
After learning about negation, we now look at how to combine two statements. The most common ways to combine them are using conjunction (AND) and disjunction (OR).
The conjunction of two statements p and q is written as p ∧ q, and is read as "p AND q". The result is true only when both p and q are true.
if (isLoggedIn && isAdmin) { ... } runs only if both conditions are true.A Truth Table with two variables will always have four rows. To construct a truth table with two variables, you create two columns, one for each variable. There are four possible combinations, either both statements are false, both statements are true, first statement is false and the second is true, or the first statement is true and the second is false. You can write these combinations in any order in the truth table.
Usually, you can start with the first variable and set it false, and set the second variable as false. This is your first row. For the second row, you write the first variable as false but turn the second variable to true. For the third row, you can set the first variable as true and the second as false. And finally, for the fourth row yu set both variables as true.
There is no compulsion to write these rows in any specific order. But usually truth tables are written in such a way that the bottom row has all variables as true and the top row has all the variables as false.
Click on a cell to change its value to true or false. Press the submit button when you think you have gotten it right.
| p | q | p ∧ q | q ∧ p |
|---|---|---|---|
| F | F | ||
| F | T | ||
| T | F | ||
| T | T |
Note how p ∧ q and q ∧ p are equal. Conjunction is commutative. The order of statements does not matter.
The disjunction of two statements p and q is written as p ∨ q, and is read as "p OR q". The result is true if at least one of p or q is true.
if (isWeekend || isHoliday) { ... } runs if either condition is true.Click on a cell to change its value to true or false. Press the submit button when you think you have gotten it right.
| p | q | p ∨ q | q ∨ p |
|---|---|---|---|
| F | F | ||
| F | T | ||
| T | F | ||
| T | T |
Note how p v q and q ∨ p are equal. Disjunction is commutative. The order of statements does not matter.
Notice that for conjunction, both statements must be true. But for disjunction, only one needs to be true for the whole statement to be true.
If you have two statements, p and q and you want to convey that both of them are true, you symbolize it as p ∧ q . But if you want to convey that at least one of them is true if not both, then you symbolize it as p ∨ q .