Selection Control Structure
Selection Control Structure
CONTROL
STRUCTURE
Selection Control Structure
● The IF statement is used in
representing the
SELECTION/DECISION control
structure. There are three (3) main
forms of the IF statement.
● IF-THEN-ENDIF
● IF-THEN-ELSE-ENDIF
● NESTED IF
IF-THEN-ENDIF
IF <condition> THEN
statement 1
statement 2
ENDIF
if (gender = “male”) then
print “You can be admitted”
end if
IF-THEN-ELSE-ENDIF
IF <condition> THEN
statement 1
statement 2
ELSE
statement 3
statement 4
ENDIF
.
.
if (age <= 18) then
fee = 40
else
fee = 100
end if
..
NESTED IF
IF <condition1> THEN
statement 1
ELSE
IF <condition2> THEN
statement 2
ELSE
IF <condition3> THEN
statement 3
ELSE
statement 4
ENDIF
ENDIF
ENDIF
IF-THEN-ENDIF(FLOWCHART)
START
STATEMENT 1
STOP
IF-THEN-ELSE-ENDIF(FLOWCHART)
START
STATEMENT 3 STATEMENT 1
STATEMENT 4 STATEMENT 2
STOP
NESTED IF
START
F CONDITI T
ON 1
F CONDITI T STATEMENT 1
ON 2
F CONDITI T STATEMENT 2
ON 3
STATEMENT 4 STATEMENT 3
STOP
Selection Statement
● ALGORITHM 1 ● ALGORITHM 2
F CONDITI T
ON 1
F CONDITI T STATEMENT 1
ON 2
F CONDITI T STATEMENT 2
ON 3
STATEMENT 4 STATEMENT 3
STOP
Questions (cont’d)
5. Write a pseudocode and construct a
flowchart to read values into the variables
A, B, and C. Print the largest of the of the
numbers.
6. Write a pseudocode and construct a
flowchart to read an integer value for
GRADE. The algorithm should print “PASS”
if the grade is greater or equal than 60
and “FAIL” if the grade is less than 60.
5. Write a pseudocode to read values into the
variables A, B, and C. Print the largest of the of
the numbers.
Start
Read A
Read B
Read C
If A > B Then
If A > C Then
Print “The largest number is “, A
Else
Print “The largest number is “, C
End if
Else
If B > C Then
Print“The largest number is “, B
Else
Print “The largest number is “, C
End if
End if
Stop
Questions (cont’d)
7. Write a pseudocode and construct a flowchart
to read an integer value for MARK and print the
appropriate grade based on the following:
MARK GRADE
80 or more A
Less than 80 but 65 or more B
Less than 65 but 50 or more C
Less than 50 but 45 or more D
Less than 45 F
Algorithm grade
Start
Declare mark as integer
Print “Please enter mark obtained”
Read mark
If mark >=80 Then
print “You got and A”
Else if mark >= 65 Then
print “You got a B”
else if mark >= 50 Then
print “You got a C”
else if mark >= 45 Then
print “You got a D”
else
print “You got a F”
end if
end if
end if
End If
Stop