You are on page 1of 23

COMPROG2

Computer
Programming 2
Evaluation of Expression
Using Operators

ROMMEL L. DORIN
Contents

Decision Structures

Relational, Logical, Conditional Operator


Objectives
To be able to use selection structure
in pseudocode and flowchart
Code a selection structure using if
statement
To use a comparison operator in a
selection structure’s condition
To use a logical operator in a
selection structure’s condition
3
Objectives
To code a nested selection structure
To be able to recognize common
logic errors in selection structures
To use a Special Case Structure for
multiple alternative in pseudocode
and flowchart
To be able to code a multiple-
alternative selection structure.
4
Decision Structure

Programs that need


the computer to
make a decision
require the use of the
selection structure
(also called the
decision structure)
Decision Structure

The Decision structure indicates that a


decision (based on some condition) needs to
be made, followed by an appropriate action
derived from that decision.
Conditional Statement

Selection structure uses conditional


statement because it executes only if the
value of the relational expression is true. If
the value of the relational expression is
false, then the conditional statement is not
executed.
Decision structures
Relational Operators
A relational operator determines whether a
specific relationship exists between two values.
Logical Operators

Logical operators connect two or more


relational expressions into one or reverse the
logic of an expression.
Logical Operators
Logical AND operator
It takes two Boolean expressions as operands and
creates a Boolean expression that is true only when
both subexpressions are true.
Logical Operators
Logical OR operator
It takes two Boolean expressions as operands and
creates a Boolean expression that is true when either
of the subexpressions is true.
Logical Operators
Logical NOT operator
It is a unary operator that takes a Boolean
expression as its operand and reverses its logical
value.
Logical Operators
Precedence of Logical Operators

! Not
&& AND
|| OR
Logical Operators
a=3;

a+=3; a=a+3
a--; 6
a; 5
++a; 6
a++; 6
a; 7
Precedence of Operators

Precedence of Logical Operators


Review
Review
If a = 2, b = 4, and c = 6, indicate whether
each of the following conditions is true or
false:
Review
If a = 2, b = 4, and c = 6, j=true, k=false
F) !(a != 5-3) && !k || (c < 10)
true true true

G) (b == ++a) || !(( 10 >= b+c) && !j)


false true false

H) ((10 != a) || (c <= a)) && k


false false

false
Review
Review
Review
Review

You might also like