When designing algorithms, it is important to make sure that all the steps are presented in the correct order. This is known as sequencing, and can be displayed in pseudocode or flow diagrams.
There are two ways of representing algorithmA sequence of logical instructions for carrying out a task. In computing, algorithms are needed to design computer programs.:
pseudocode Also written as pseudo-code. A method of writing up a set of instructions for a computer program using plain English. This is a good way of planning a program before coding.
a flow diagram (also known as a flowchart)
Representing sequencing in pseudocode
Writing in pseudocode is rather like writing in a programming languageA language used by a programmer to write a piece of software. . Each step of the algorithm is written on a line of its own, in sequence.
Consider this simple algorithm for calculating how old a dog is in dog years. It contains three steps, all in sequence:
ask how old the dog is in human years
multiply human years by seven to find out how old the dog is in dog years
print the answer on the screen
In pseudocode, the algorithm would look like this:
OUTPUT 'How old is your dog?'
INPUT user inputs their dog's age in human years
STORE the user's input in the human_years variable
dog_years = human_years * 7
OUTPUT 'In dog years, your dog is aged' + dog_years