AND operator is used to determine if two or more conditions are true. If all the conditions are true, the AND operator returns TRUE. If any one of the conditions fail, the AND operator returns FALSE. In some programming languages AND operator is denoted by “&&” symbol.
For example - you should go to bed only after you have completed your homework and the time is past 8 PM.
Here, if we want to derive the logical operation from this scenario, we have the following conditions:
Condition 1: Have you completed homework?
Condition 2: Is the time past 8 PM?
And the decision we are deriving is:
Decision: Should you go to bed?
Based on this we can write the below pseudo code:
IF (Homework completed) AND(Time is past 8 PM)
THEN
Go to bed
ELSE
Do not go to bed
END
Let us now try to see the different combinations possible with the above pseudo code.
Condition 1 |
Condition 2 |
Decision |
Have you completed homework? |
Is the time past 8 PM? |
Should you go to bed? |
Yes |
Yes |
Yes |
No |
Yes |
No |
Yes |
No |
No |
No |
No |
No |