← Back to Articles

Pseudocode

Jamie Z 2025-04-22

Learning Goals

  • Understand how algorithms can be developed in different ways
  • Understand algorithm constructs
  • Be able to communicate using pseudocode

Developing Algorithms

Flowchart

  • A diagram that shows the logic of a set of instructions.
  • Developed using specific shapes and flow lines.
  • Each Flowchart shape represents a specific aspect or process.

Pseudocode

A step-by-step description of an algorithm.

  • Written using simple English with key words that can sometimes be linked to programming.
  • Pseudocode has some basic rules about layout and structure.

Pseudocode will be used as the formal method of symbolising algorithms in Digital Solutions. Pseudocode is a descriptive method used to represent an algorithm and is a mixture of everyday language and programming conventions.

Commonly used key words

  • START

  • DECLARE

  • SET

  • TO

  • INPUT

  • IF, THEN, ELSE

  • ENDIF

  • GREATER THAN

  • GREATER THAN AND EQUAL TO

  • LESS THAN

  • EQUAL TO

  • OUTPUT

  • FOR

  • END FOR

  • WHILE

  • END WHILE

  • END

What are Algorithm Constructs? (Building Blocks of Pseudocode)

There are basic building blocks that an algorithm consists of. Each of them serve a particular purpose.

  1. Sequence

  2. Assignment

  3. Selection and Condition (IF, IF ELSE)

  4. Iteration

  5. Functions

Sequence

  • A set of instructions that are processed one after the other.
  • For example, a ‘brushing teeth’ algorithm could use this sequence:
  1. put toothpaste on toothbrush
  2. use toothbrush to clean teeth
  3. rinse toothbrush

It is crucial that the steps in an algorithm are performed in the right order - otherwise the algorithm will not work correctly.

Assignment

  • Assignment is when we store the value of an expression in a variable.

  • It is very similar to what you would have seen in maths e.g. x=5. (5 is the value being stored as x)

  • In programming, this is exactly the same idea, except computers can remember anything not just numbers, ALSO in programming the variables are given meaningful names that relate to the data they contain e.g. studentName = “Tom”.

Selection and Condition

  • A selection statement uses a condition to select which line of the program will be used next.
  • Mario wins = show message ‘Mario wins the trophy!’
  • To display the message, the condition is that Mario must win.

These statements help to make decisions and change the flow of a program. Selection statements check whether a condition is true, i.e. Is it true that Mario won?

Iteration

Iteration is also called repetition and is used when something is repeated over and over again, so the program goes round in a loop.

  • Key words for loops include WHILE, REPEAT and FOR statements.
  • A FOR loop is used when it is known exactly how many times to go round the loop.
  • A WHILE loop is used to repeat while a condition is true or false.
START
    FOR 7 steps
        INPUT Jump up and forward
    ENDFOR
END

Modularisation

Modularisation is used to reduce the complexity of a system by deconstructing it into more or less independent units or modules by using Functions. Functions are important because they allow us to take large complicated programs and to divide them into smaller manageable pieces and more easily maintained.

Pseudocode example:
FUNCTION delivery_charge
    CALCULATE totalCost
    IF (totalCost > $10)  THEN
        OUTPUT  ‘no delivery charge’
    ELSE
        OUTPUT  ‘$5 delivery charge’
    ENDIF
        OUTPUT  ‘thankyou’
END FUNCTION

IPO Charts

  • An IPO Chart is used to layout the Inputs, Processes and Outputs of functions in your data driven application.
  • As seen in the example below the DFD (These will be covered in more detail later) is a graphical representation of how/what data is handled in the application. We will learn about DFDs next term

The IPO Chart takes this one step further:

  1. In the process column, you actually write the pseudocode for the process in the application and how it will work.

  2. If you have multiple processes, you would have multiple IPO charts.

  3. Once the algorithm is desk checked it can then be converted to the code of your choice to create a functioning process in your data driven application

Pseudocode IPO chart

Use pseudocode to develop an algorithm for this guessing game. Your pseudocode should allow anyone to play this game, even if they have never heard of it before. Present your Algorithm in an IPO Chart Test your algorithm – Play the game!

Input Process Output
Guess START DECLARE Number SET Number to 2 WHILE Guess IS NOT Number IF INPUT Guess IS GREATER THAN Number OUTPUT Thumbs Down ELSE IF INPUT Guess is LOWER THAN Number OUTPUT Thumbs Up ENDIF ENDWHILE OUTPUT “You win” END - Thumbs Up - Thumbs Down - You win

Code VS Pseudocode