PSEUDOCODE AND
FLOWCHART ON
SELECTION CONTROL
STRUCTURES
TOPIC III
Else if statements
Nested if statements
Logical Operators
WHAT IS AN ELSE IF STATEMENT?
As its name suggests, is a combination of if
and else . Like else , it extends an if
statement to execute a different statement in
case the original if expression evaluates to
false .
else if statement is used to specify a new
condition if the first condition is false .
LOGICAL OPERATORS
Before we proceed in understanding else if
statement first we need to learn what are
logical operators. In the last topic we
discussed what control structures are but did
you know that you can have multiple
condition/expression in a single if statement.
Like if you have 1 variable named “num” and
want to know if “num” is a positive and an
even number at the same time.
To check for this condition you need to use a
LOGICAL OPERATORS
A logical operator is a symbol or word used to
connect two or more expressions such that
the value of the compound expression
produced depends only on that of the original
expressions and on the meaning of the
operator. Common logical operators include
AND, OR, and NOT.
LOGICAL OPERATORS
We know that if the condition/expression is
true then it will execute the block of code
inside of that if statement so if you have 2 or
more condition do they have to be all true for
it to execute what is inside the if statement?
It all depends on what logical operator are
you using.
LOGICAL OPERATORS
• AND operator will return true if all
condition / expression are true.
• NOT operators is different from AND or
OR operators they do not connect
expression instead they return the opposite
of the a single condition / expression, if the
condition is true then it will return false
and if it is false it will return true.
• OR operator will return true if at least 1
condition or expression is true.
LOGICAL OPERATORS
Now let’s go back to the example we need to solve
from the previous slide.
You have 1 variable named “num” and want to know
if “num” is a positive and an even number at the
same time.
First lets analyze what is ask: to check if num is
positive and even at the same time. To solve this we
need to use condition expression that check if num is
positive and even.
• Condition to check if num is positive: num > 0
• Condition to check if num is even: num % 2 == 0
• Connect the 2 condition using operator AND:
PSEUDO CODE
EXAMPLE OF ELSE IF
STATEMENT WITH
LOGICAL OPERATOR
Find the highest inputted
numbers (variables: x, y and
z). Assuming all inputted
numbers are not the same.
FLOWCHART EXAMPLE
OF ELSE IF STATEMENT
WITH LOGICAL
OPERATOR
Find the highest inputted
numbers (variables: x, y and
z). Assuming all inputted
numbers are not the same.
PRECEDENCE LEVEL IN LOGICAL
OPERATORS
The order of precedence is: logical complements ( Not )
are performed first, logical conjunctions ( And ) are
performed next, and logical disjunctions ( Or ) are
performed at the end. So if x = 1, y = 2 and z = 3 and
an expression of: NOT x < y AND y > z OR x < z
• Step 1: truth value of NOT x < y = False
• Step 2: truth value of NOT x < y AND y > z = we now
know that NOT x < y is False and we proceed to y > z
= False, thus the expression is False AND False =
False,
• Step 3: truth value of False OR x < y = True, False
OR True = True
NOT x < y AND y > z OR x < z
NOT 1 < 2 AND 2 > 3 OR 1 < 3
WHAT IS A NESTED IF STATEMENT?
Nested if is a decision-making statement that
works similar to other decision-making
statements such as if, else, if..else, etc. It
executes a block of code if the condition
written within the if statement is true.
However, in the nested-if statement, the
block of code is placed inside another if block.
PSEUDO CODE
EXAMPLE OF NESTED
IF STATEMENT
Find the highest inputted
numbers (variables: x, y and
z). Assuming all inputted
numbers are not the same.
FLOWCHART EXAMPLE OF
NESTED IF STATEMENT
Find the highest
inputted numbers
(variables: x, y and
z). Assuming all
inputted numbers are
not the same.