Not all algorithms will become programming code, but all programming code comes from an algorithm. This is because programming code is logical and must follow a set of logical steps to solve a problem or reach a goal. There are a number of ways to express an algorithm, but one in particular that is used at both GCSE and A Level is Pseudocode. Pseudocode literally means “not real” code – instead it is just the logic of the algorithm written down using a set of grammatical rules, or syntax. Although it is entirely possible to write out your algorithm in pseudocode straight away, you may find it easier to use the process of going from Structured English >> Pseudocode >> programming code. Each evolution of your code moves a little further away from Natural Language (the language that you and I speak as humans) and closer to Machine Language (the language that your computer uses). Let’s have a look at an example: If we were to write out an algorithm that outputs the times tables up to ten of any number, in Structured English it might look like this:
The user INPUTS a number which is saved as num
FOR each number from 1 to 10, OUTPUT num * numberNotice that we appear to be using logical key words in our description here and they are highlighted by writing them out in capital letters. Now we have an idea of the logic, we can remove some of the detail and make our more logical pseudocode version:
Num : INTEGER Num <-- INPUT FOR Number <-- 1 TO 10 DO OUTPUT Number * Num NEXT Number This is far more like actual programming language with just a few variations. We still put our key words in capital letters just like we did in the Structured English version, but this time we declare the variables (give them a name & data type) and use programming constructs like FOR loops and OUTPUT. Let’s see what this looks like when we translate it into Python:
Num = int(input("Please enter a number: )) for Number in range (1,11): print(Num*Number It’s quite a bit smaller in the final version of the code as we use syntax that is less wordy and more like the logical commands that a computer would understand. So what do we need to know about these key words that Pseudocode uses? Download the free Pseudocode Cheat Sheet for a list of how to use the key terms.