Psuedocode

Psuedocode is a way of representing algorithms and code without having to worry about language specifics. There are literally hundreds of languages which all end up producing similar code. Rather than having a algorithm, such as bubblesort, written in every language we could write it using a independent language which does not care too much about things like semi-colons or brackets!

The goal of psuedocode is to represent code without worrying about the details of how it will work. It is a mixture of code and English which allows us to represent some very complex ideas in very simple code.

Psuedocode will contain the following elements -

Variables – These are un-typed which means you do not have to specify a data type. This will be assumed by the reader.
Iteration
– This is represented by FOR, WHILE or REPEAT / UNTIL
Selection
– This is represented as IF...THEN....ELSE
Methods
– This is represented as methodName(parameter). It is untyped.
Output
– PRINT or OUTPUT will display on the screen

a = 0
file = OPEN( “file.data”, RW)
WHILE a < 30
            FOR j = 0 to 10
                        WRITE file, “j”
            NEXT
             PRINT a
            a = a + 2
END WHILE
CLOSE (file)

The above code will open a file in read-write mode. Then write the numbers 0 to 10 to the file 15 times. Notice that the variable a is incrementing by 2. It will also output a just before it is incremented so it will output the pattern “0, 2, 4, 6...”

The key to psudocode is in the lack of detail! How does “OPEN” work? We do not care! We are only interested in that fact that it opens a file for writing. Using methods in this way we can hide a lot of the details of how to implement the algorithm and simply concentrate on the purpose.

Unless you are reading the Java mini-site you should assume that all code will be in psudocode unless otherwise stated.

Important note – All A-Level exams will expect you to be able to read and write in psudocode rather than Java.