teach-ict.com logo

THE education site for computer science and ICT

3. The need to be precise

Pseudocode is a text-based way of setting out an algorithm. It is not a formal computer language and so has no particular rules on how to write it. However, we will be describing good practice.

Pseudocode needs to be as unambiguous as possible to make it clear how the algorithms works.

Pseudocode is often used to describe an algorithm that is going to be part of a computer program and so the programmer who is reading the pseudocode needs a clear explanation of what is required.

For example you could write out pseudocode on making a cup of tea like this:

  • Fetch a tea cup
  • Boil some water
  • Place a tea bag into the cup
  • Pour on boiling water
  • Stir teabag
  • Remove teabag
  • End

The pseudocode 'boil some water' is not very clear - how much water needs to be boiled? Also 'pour on boiling water - but how much? 'Stir teabag' - but for how long?

A more precise bit of pseudocode would be :-

  • Fetch a tea cup
  • Boil at least 200cc of water
  • Place a tea bag into the cup
  • Pour on boiling water up to 3/4 full
  • Stir teabag for 10 seconds
  • Remove teabag
  • End

Note the 'End' statement - this confirms that the algorithm has been fully laid out. You could also number each step, should that be useful for referring to a particular line for example, but it is not essential.

If the task of the computer programmer was to write code for controlling a tea-making robot, this extra precision is essential.

 

Challenge see if you can find out one extra fact on this topic that we haven't already told you

Click on this link: what is pseudocode