Previously we have learnt how to represent an algorithm (a sequence of steps) using a flow chart diagram. Each step of an algorithm can also be represented by a set of worded instructions called a line of code. There are many different representations of code, called programming language. These include Python, Scratch, Java, and C. We use programming language to communicate with computers to give them the instructions that we want them to perform.
A programming language usually consists of
Statements - which give an instruction for the action - written as capital letters
Expressions - which represent a value
Before translating an algorithm into a specific programming language, the steps of the algorithm can be written as pseudocode. Pseudocode is easy to read coding language that can’t be used by a computer but can be easy to follow for humans to check and make sure the program will work before writing into a specific computer language.
There is no strict set of standard notations for pseudocode, but some of the most widely recognised are:
\text{INPUT} - indicates a user will be inputting something
\text{OUTPUT} or \text{PRINT} - indicates that an output will appear on the screen
\text{SET} - assign an initial value to an expression
\text{IF - THEN - ELSE} - a decision (selection) in which a choice is made
Any instructions that occur inside a decision are usually indented.
Look at the pseudocode below.
What value is printed at the end of the code?
Consider the rectangle shown in the image. The dimensions of the rectangle are W metres and L metres.
What does the following pseudocode calculate?
Note: the symbol * represents multiplication.
What value is printed at the end of the code?
Common notations for pseudocode:
\text{INPUT} - indicates a user will be inputting something
\text{OUTPUT} or \text{PRINT} - indicates that an output will appear on the screen
\text{SET} - assign an initial value to an expression
\text{IF - THEN - ELSE} - a decision (selection) in which a choice is made
When a decision is to be made between two alternatives in code, we can use the \text{IF – THEN – ELSE} statement.
Look at the pseudocode below:
What statement is printed at the end of the code? Note: the symbol / represents division.
\text{IF – THEN – ELSE} statements are used for making a decision between two alternatives.