What is computational logic?
What is computational logic or computational thinking?
Computational logic is a term that describes the decision-making progress used in programming and writing algorithms; in other words, computational thinking is a way of looking at problems that allows a computer to help us solve them.
Computational thinking is made up of four processes:
- Decomposition breaks down a problem into smaller parts that are easier to understand
- Pattern recognition means looking for similarities among different problems and within the same problem
- Through abstraction we decide what information to focus on when solving a particular problem
- By writing an algorithm we develop a set of instructions to help us solve the problem.
Computational thinking in KS1
Computational logic is at the root of everything done in computing and when students first start learning about writing algorithms they will look at something called a flow chart. A flow chart essentially allows us to define an algorithm by using two key components, processes and decisions.
- A process is when we do something
- A decision is when we make a choice
For example, you may have a decision in a flowchart that asks whether it is the weekend or not. We then have a control flow to our program using arrows that leads to two different processes. On one side of the decision is our yes option, which could point to a process telling us to have a lie-in. On the other side of the decision would be the no option, which would point to an option telling us to get up for work. A process is a rectangle and a decision is a diamond.
In KS1 your child will learn about the decision-making processes that are involved in computer science two ways.
- Students will learn to write a flow chart for everyday tasks such as brushing their teeth and the decision making process may be as simple as asking whether they like to wet their toothbrush before they brush.
- Alongside this design of flow charts your child will also start to learn programming using a turtle robot such as the Bee-Bot.
Your child might be asked to draw the following path out using the keypad on the Bee-Bot:
The large arrow shows the start position and direction of the robot, while the black lines show the path that the robot should take. We can use the keypad on the left to control our robot by pressing buttons in the correct sequence and then running the program.
In order to get the robot to follow the path we would have to:
- first press the up (forward) key
- followed by the turn left key
- followed by the up key again.
This would make the robot follow the given path correctly when the run button was pressed.
This type of algorithm writing also requires a decision-making process that constitutes computational logic; the decision is made when the algorithm is written (deciding to turn left instead of turning right or going forwards again).
Computational thinking in KS2
In KS2 computational logic is applied much more practically to the design of software.
The majority of primary schools use Scratch as a tool to teach their students about programming. Scratch is a visual programming language designed to teach the basic concepts required to start writing programs and computer games.
In a game there are a lot of decisions to be made. When discussing computational logic in a programming-specific sense, we refer to decisions as conditions. In their purest form, conditions are a test with different outcomes and programming a condition is commonly referred to as an if statement.
Computational logic: a practical problem for KS2 children
For this practical project we are going to look at some Scratch code that builds a very basic turtle robot that is able to draw paths on our screen based on some user input. You can run the project yourself on Scratch.
There are three user inputs that we are going to test for:
1. If the user is pressing the forward arrow, move 10 steps forward
2. If the user is pressing the left key, rotate 15 degrees anti-clockwise
3. If the user is pressing the right key, rotate 15 degrees clockwise
Let’s have a look at some of the basic Scratch blocks we are going to use:
And now let’s take a look at the Scratch code which will allow our game to work:
The code looks rather complex, however when we break it down step-by-step it is really quite simple.
- When the flag is pressed the first thing we run is code to set the position and direction of our character on the screen.
- Next we clear any pen and set the colour of the pen. This only happens once, as it is not inside a loop.
- Inside our loop we are constantly checking for a number of conditions to be true. The first thing we check is whether any of the arrow keys have been pressed. If they have, respond with the correct movement by going forward or turning in the correct direction.
- The next thing we check for is whether the space key is pressed and if it is, we respond by putting our pen down onto the screen. This is a new type of block that also includes something called an 'else'. In an if/else block we run the code in the else section only if the condition in the if section isn’t true. We need this code here because once we have put our pen down, it isn’t raised again until we call the code that lifts our pen back up. If we just had an if statement here then we would put our pen down the first time the space is pressed and never lift it up again. By having an else, we are also testing for when the space bar is no longer pressed and responding by lifting the pen. Our last bit condition simply checks whether the r key is pressed and when it is, clears all pen off of the screen.
The code above seems quite complex at first, however when broken down into individual steps and read through in plain English, it actually makes perfect sense. This is true of most conditions and your child will learn how to write computational logic by first breaking a problem down into plain English.
For example, you may ask what will happen when your character hits an enemy in the game. You have decided that this should restart the level and in plain English this would be written as: “if the player collides with enemy, restart the level”. This logic can then be written into a flow chart and then into Scratch code to make your game work.
How your child is introduced to computational logic in primary school
Please note that the following guidelines for what is taught in each primary year is for guidance only and may not be representative of the way computing is taught at your child’s school.
Your child will be introduced to writing simple flow charts that include some basic decision making.
Your child will use a turtle robot and will write computational logic to decided what command to run next.
If using a visual programming language, students will start to implement very simple logic such as yes and no answers.
Students will start to write code that can respond to a variety of conditions being true or false (if/then statements).
Year 5 and Year 6
The concept of computational logic will be expanded further to build complex programs and games that students plan and build themselves using Scratch or another visual programming language.