0% found this document useful (0 votes)
12 views36 pages

Quarter 3 Week 1 Boolean Values and Expressions

This lesson covers Boolean expressions, relational comparison operators, and logical operators such as AND, OR, and NOT. It explains how to use these operators in programming, particularly in C++, and provides examples of their usage and expected outputs. The document emphasizes the importance of understanding operator precedence and the true/false evaluations in selection structures.

Uploaded by

iremischyro
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views36 pages

Quarter 3 Week 1 Boolean Values and Expressions

This lesson covers Boolean expressions, relational comparison operators, and logical operators such as AND, OR, and NOT. It explains how to use these operators in programming, particularly in C++, and provides examples of their usage and expected outputs. The document emphasizes the importance of understanding operator precedence and the true/false evaluations in selection structures.

Uploaded by

iremischyro
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 36

IN THIS LESSON, YOU WILL LEARN ABOUT:

• 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.

Greater – than Evaluates as true when the left operand


> operator is greater than the right operand.

Less – than Evaluates as true when the left operand


< operator is less than the right operand.
Relational Comparison Operators
Operator Name Discussion
Greater-than- equal-to operator
>= or equal-to
operator
Evaluates as true when the left operand is
greater than or equivalent to the right
operand.
Less-than-or- Evaluates as true when the left operand is
<= equal-to
operator
less than or equivalent to the right
operand.

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

Greater Than (>) Over, above, more than,


Lesser Than (<) Below, lesser
Greater or equal (>=) NO less than, AND
above, AND more, NOT
under, at least
Lesser or equal (<=) NO more than, AND
below, AND lesser, at
most
X is no more than 4 X <= 4

X is at least 4 X >= 4

X not under 4 X >= 4

X is 4 and above X >= 4

X is at most 4 X <= 4
C++ Boolean Values

• bool data type


• returns 1 if true and 0 if
false
C++ Boolean Values

bool isCodingFun = true;


bool isFishTasty = false;
cout << isCodingFun;// Outputs 1 (true)
cout << isFishTasty;// Outputs 0 (false)
C++ Boolean Expressions

• returns 1 if true and 0 if false


• use the comparison
operators and/or the logical
operators
C++ Boolean Expressions
int x = 10;
int y = 9;
cout << (x > y); // returns 1 (true),
because 10 is higher than 9

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

You might also like