Computational Thinking
Computational Thinking
Used to show the direction of flow, which is top to bottom and left to
right.
Used when a decision has to be made; the decision should be written
inside the diamond and there are two possible outcomes
1 of 7
Example of a flowchart where user inputs two numbers, adds them and outputs the result.
Example of a pseudocode where user inputs two numbers, adds them and outputs the result.
OUTPUT “enter the two numbers”
INPUT number1
INPUT number2
Total number1 + number2
OUTPUT “The total of the two numbers is”, Total
2 of 7
SELECTION
➢ Selection is a programming construct with more than one possible pathway; a condition is
tested (using a question or criterion) before deciding which pathway to follow (the output)
➢ A condition is something that is checked to determine whether it is true or false
➢ Selection is achieved using IF statements.
➢ When using selection in any programming language, comparison operators are used to
compare values.
➢ Comparing different values gives programs the ability to determine whether something is
true or false and then decide which path to take next.
Flowchart example
3 of 7
Class activity
1. Write a pseudocode to match the flowchart algorithm above.
2. Complete the table below and add the variables and data types that will be required when
creating the program.
Variable name Data type
Adult FALSE
Cost 7.95
OUTPUT ("Enter the activity")
INPUT Activity
OUTPUT("Enter your age")
INPUT Age
IF Age >= 18
THEN
Adult TRUE
ENDIF
IF Adult = TRUE
THEN
Cost 9.50
ENDIF
OUTPUT("As you are", Age, "it will cost you", Cost, "to go",
Activity)
4 of 7
CONDITIONAL OPERATOR
They are used to carry out comparisons between two values.
Operator What it means
= Equal to
< Less than
> Greater than
<= Less than or equal to
>= Greater than or equal to
!= Not equal to
2. IF…THEN…ELSE
The syntax
IF statements with an ELSE clause are written as follows:
IF <condition>
THEN
<statement or list of statements to be carried out>
ELSE
<alternative statement or list of alternative statements to be carried out>
ENDIF
5 of 7
3. Nested IF statement
This is an IF condition within another IF.
With an IF statement we follow the THEN part when the IF statement is true but we only follow
the ELSE part if the IF statement is false.
Example
Consider marks of 34, 45, 62 and 78.
Always make sure that the number of ENDIFs matches the number of IFs and that they are
indented to match. Always make sure the ELSEs are in line with the THENs.
6 of 7
Class activity
Write a pseudocode for the following flowchart
7 of 7