Module 3: Decision Structure Flashcards
An operator that determines whether a specific relationship exist between two
values.
The Relational Operator
Operator for greater than
>
Operator for less than
<
Operator for greater than or equal to
> =
Operator for less than or equal to
<=
Operator for equal to
==
Operator for not equal to
!=
Explain the difference between == and =
The double equal(==) is a relational operator which can use for comparison. The
boolean expression have a value of true or false. While the single equal (=) is an
assignment operator that uses to assign a value to the variable
What is the value of the following expression?
int a = 5
a == 10
False
int a = 5
a = 10
The value of a is simply changed to 10.
How many variables does the left side of an expression must have when using the assignment operator?
Only single variable
Which one is valid?
a. c = 5
b. c+d= 5
a is valid, b is invalid.
Also known as Boolean operators, operate on Boolean values to
create a new Boolean value.
Logical Operator
Sometimes, a statement is executed is determined by a combination of
several conditions. What can you use to combine these conditions?
Logical Operator
What is the name of the ! operator?
not
Rule of the ! operator
Opposite of the expression
Name of && operator
And
Rules of && operator
One false, all false
Name of || operator
Or
Rules of || operator
One true, all true
What would be the result?
20 > 18 && 49 < 50
20 > 18 = True
49 < 50 = True
The expression uses the && operator (one false, all false). Therefore the result is true.
What would be the result?
kg = 49
age = 20
20 > 30 || 49 < 51
20 > 30 = False
49 < 51 = True
The expression uses the || operator (one true, all true). Therefore, the result is true.
What is the precedence of the logical operators?
AND (&&) - Highest
OR (||)
NOT (!) - Lowest
What would be the result of the following expression?
!(3>4)|| !(12>4) && !(4>1)
!(3>4)|| !(12>4) && !(4>1)
!(False) || !(True) && !(True)
True || False && False
True || False
True