Selection Logic
Selection Logic
Selection Logic
Solving Problems using Selection Logic (I.P.O. Chart and Pseudocode Algorithm)
Selection Logic
◦ We have learnt to solve problems using sequence /straight line
logic -solutions whose statements are executed in a sequence from
the first to the last.
Just Click for the Caribbean 3rd Edition Howard Lincoln, Alison Page Et al.
Logical test/Condition
◦ A Logical test is one that has the answer yes or no, or true or false.
◦ ‘How old are you?’ is not a logical test, because it can have many different
answers.
◦ ‘Are you under 20?’ is a logical test, because it has the answer yes or no.
Just Click for the Caribbean 3rd Edition Howard Lincoln, Alison Page Et al.
Logical test
◦ Logical test use a relational operator to compare two values.
Relational Operators Meaning
= equals to
◦ The comparison gives a yes/no response which decides which of two actions is taken.
Just Click for the Caribbean 3rd Edition Howard Lincoln, Alison Page Et al.
Decisions
In pseudocode, the conditional structure begins with the words:
If … then
The Logical test goes between the words ‘If’ and ‘then’.
Just Click for the Caribbean 3rd Edition Howard Lincoln, Alison Page Et al.
Decisions
The instruction(s) that need(s) to be executed if the Logical Test is true is inserted on the next line but indented.
The indentation shows the instruction(s) that need to be executed if the condition is met.
OR
OR
OR
If <<Logical test>> then
<<Statement#1 if Logical Test is true>>
…
<<Statement#last if Logical Test is true>>
Else
<<Statement#1 if Logical Test is false>>
…
<<Statement#last if Logical Test is false>>
Decisions
The word EndIf (or End If) indicates the end of the conditional structure
OR
If <<Logical test>> then
<<Statement#1 if Logical Test is true>>
…
<<Statement#last if Logical Test is true>>
Else
<<Statement#1 if Logical Test is false>>
…
<<Statement#last if Logical Test is false>>
EndIf
Let Us Create a Pseudocode Solution With A Problem
Problem-
Write a program that accepts a student’s mark. If the mark is greater
than or equal to 50 the student passes and fails if their mark is less
than 50. This program must print if the student passed or failed.
I.P.O. Chart/Defining Diagram
Input Processing Output