Quarter 3 Week 1 Boolean Values and Expressions
Quarter 3 Week 1 Boolean Values and Expressions
• Boolean expressions
• The relational comparison and logic
operators
– AND logic
– OR logic
– NOT logic
• Precedence when combining AND and
OR operators
BOOLEAN
EXPRESSIONS
AND THE
SELECTION
STRUCTURE
Boolean
Expression
⮚an expression whose value can
be only true or false (yes or no,
1 or 0, on or off switches)
⮚ used to control every
selection structure
Boolean
Expression
⮚ after
Mathematician
George Boole
(1815–1864)
⮚ the father of
information age
USING
RELATIONAL
COMPARISON
OPERATORS
Relational Comparison Operators
Operator Name Discussion
Equivalency Evaluates as true when its operands are
= operator equivalent. Because the assignment
operator in many languages is the equal
sign, those languages often use a
double equal sign (==/===) as the
equivalency operator to avoid confusion
with the assignment operator.
Not-equal-to
<>/!=
Evaluates as true when its operands are not
operator equivalent. Some languages use an
exclamation point followed by an equal sign
(!=) as the not-equal-to operator. In a
flowchart or pseudocode, you might prefer to
use the algebraic not-equal to symbol (≠) or
to spell out the words “not equal to.”
If:
x represents the
left operand x=5
y=9
x>y
y represents the
right operand
If:
x represents the
left operand
x = “jack”
y = “JACK”
x == y
y represents the
right operand
If:
x represents the
left operand
x = “jack”
y = “june”
x<y
y represents the
right operand
BOOLEAN
RACE
If:
x represents the
left operand x=9
y=4
x>y
y represents the
right operand
If:
x represents the
left operand
x = “cat”
y = “cheese”
x => y
y represents the
right operand
If:
x represents the
left operand x=5
y = 12
x => y
y represents the
right operand
If:
x represents the
left operand x = “zoo”
y = “Zoo”
x == y
y represents the
right operand
If:
x represents the
left operand x=7
y=9
x != y
y represents the
right operand
If:
x represents the
left operand x = 100
y = .01
x<y
y represents the
right operand
If:
x represents the
left operand x = .001
y = .01
x>y
y represents the
right operand
If:
x represents the
left operand x = 100
y = 100
x != y
y represents the
right operand
If:
x represents the
left operand x = 1000
y = 1000
x ==y
y represents the
right operand
If:
x represents the
left operand x = .078
y = .780
x >= y
y represents the
right operand
If:
x represents the
left operand x = 678
y = 679
x>y
y represents the
right operand
If:
x represents the
left operand x=1
y = 100%
x ==y
y represents the
right operand
If x < y is true,
then x ___
>= y is
false.
If x > y is true,
then x ___
<= y is
false.
If x == y is true,
then x <>___
or != y is
false.
If x != y is true,
then x ___
== y is
false.
If x != y is true,
then x ___ y may
> or <
be true.
OPERATOR ENGLISH TERM / WORD
USUALLY USED
X is at least 4 X >= 4
X is at most 4 X <= 4
C++ Boolean Values
OR
int x = 10;
int y = 9;
cout << (10 > 9); // returns 1 (true), because 10
is higher than 9
DETERMINE THE OUTPUT
int x = 10;
cout << (x == 10);//1
DETERMINE THE OUTPUT
int x = 10;
cout << (x == 10); //1
cout << (10 == 15);//0
cout << (10 != 15);//1
cout << (x <= 21);//1
cout << (10 >= 15);//0
cout << (x > 10);//0
cout << (10 < 15);//1