Nested If &
Else If
Nested If
Nested if statements means an if statement inside another if
statement.
When we compare condition while staying in a condition
comparison or we create a if structure within an if structure is called
nested structure. A condition located inside a condition is called
nested condition.
Nested If-Else statements are useful to include one if…else
statement within another if…else statement to test one condition
followed by another condition.
Flowchart
SYNTAX 4
If condition Then
If nested_condition_1 Then
// Statements to Execute
Else
// Statements to Execute
End If
Else
If nested_condition_2 Then
// Statements to Execute
Else
// Statements to Execute
End If
End If
Else If Statement
▹ When there are more than two possible actions
to take we sometimes use a serial if statement.
▹ It is called Else If statement
5
How the Else If statement works?
▹ With a serial If statement each condition is
tested until one is found to be true.
▹ If a condition is found to be true the
conditional statements will be executed and
then control will be passed to the statement
following the End If.
▹ If none of the conditions stated is true the
Else branch is executed and then control will
be passed to the statement following the
End If.
Syntax 7
▹ If condition Then
▹ ‘Note: you may have one or more
statement
statement
statement
▹ ElseIf condition Then
▹ statement
▹ ElseIf condition Then
▹ statement
▹ Else
▹ statement
▹ End if
Flowchart
What does Syntax mean?
▹ In programming, syntax refers to the rules that
specify the correct combined sequence of
symbols that can be used to form a correctly
structured program using a given programming
language.
9
What is a Flowchart in programming?
▹ Flowchart is a diagrammatic representation of
an algorithm. Flowchart are very helpful in
writing program and explaining program to
others.
10
Examples of flowcharts in programming
▹ Draw a flowchart to add two numbers entered
by user.