CIS 15AG
Review Chapter 5:
Selection – Making Decisions
Logical expression
–
an expression that can be either
true
or
false
. Logical expressions
are created using relational and/or logical operators.
Relational Operators:
<
<=
>
>=
==
!=
Logical Operators:
Evaluation of logical expressions
–
complement of
==
is
!=
!(a == b)
is
a != b
–
complement of
<
is
>=
!(a < b)
is
a >= b
–
complement of
>
is
<=
!(a > b)
is
a <= b
–
complement of
&&
is

!(a && b)
is !
a  !b
(De Morgan's Rule)
!(a  b)
is !
a && !b
Precedence/
Associativity
Arithmetical
Operators
Relational
Operators
Logical
Operators
Assignment Operators
15
Right to left
+
plus

minus
!
14
Left
to right
*
/
%
13
Left
to right
+

10
Left
to right
<
<=
>
>=
9
Left
to right
==
!=
5
Left
to right
&&
4
Left
to right

2
Right to left
=
+=
=
*=
/=
%=
Expressions connected by
&&
and/or

are evaluated left to right, and it is guaranteed
that the evaluation will stop as soon as the truth or falsehood is known.
n != 0 && a / n > 10
//
when n is 0,
a / n > 10
is not evaluated, because
false
and anything is
false
TwoWay Selection
– a logical expression is evaluated; if it is true, one or more actions
is/are executed, if it is false, another action or group of actions is executed.
1
not
false
true
true
false
and
false
true
false
false
false
true
false
true
or
false
true
false
false
true
true
true
true
b
b  a
a > b
a
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '10
 Staff
 Computer Programming, Max, ASCII, Ternary Operator, printf, control character

Click to edit the document details