Learn
Logical Operators
Logical Operator: &&
The and
logical operator is denoted by &&
.
It returns true
if the condition on the left and the condition on the right are both true
. Otherwise, it returns false
.
Here’s the truth table:
a | b | a && b |
---|---|---|
false | false | false |
false | true | false |
true | false | false |
true | true | true |
For instance:
( 1 < 2 && 2 < 3 )
returnstrue
( 1 < 2 && 2 > 3 )
returnsfalse
Note: The keyword and
can also be used in the place of &&
.
Instructions
1.
Write the following if
statement:
- If
hunger
istrue
andanger
is true, then print out the word"Hangry"
.