1 of 8

Algorithms:

Pseudo Code

3

2 of 8

Engage

What is the differences between the two codes below?

2

3 of 8

Pseudo Code

Learning Objective:

Understand the use of pseudo code and how to write it.

Learning outcome:

To be able to read and write pseudo code for a particular problem.

3

4 of 8

iCan()

iCan.Explore()

I show an understanding of the topic by briefly describing my understanding

iCan.Enhance()

I show a good technical understanding and am able to show this through detailed description and evaluation of effectiveness.

iCan.Excel()

I can show an excellent technical understanding of the topic and can give factually correct examples and evidence.

4

5 of 8

Pseudo code

Pseudocode is a style of algorithm writing that should be adaptable to any program language. There are not set rules for how to write pseudocode but it should be readable by any programmer.

What are the benefits of pseudo code?

5

INPUT is sugar required

IF (sugar is required)

THEN OUTPUT add sugar

ELSE

OUTPUT don’t add sugar

ENDIF

6 of 8

Writing Pseudo code

  1. All key components should be written in all caps.
  2. INPUT is used for all inputs
  3. OUTPUT is used for all outputs (print is an output example)
  4. Statements such as IF, Loops and Function should have an END statement to identify the length of the statement
  5. If your not sure how to write something, write it in plain english. (e.g. get random number between 1-6)
  6. There is no one set way to write pseudo code.

6

INPUT is sugar required

IF (sugar is required)

THEN OUTPUT add sugar

ELSE

OUTPUT don’t add sugar

ENDIF

7 of 8

Benefits of Pseudo code

  • Pseudo code is quick to write (with practice) and makes programming faster.
  • It can be easily be translated into any programming language.
  • More easily understood than programming code to a non specialist.
  • No time wasting testing code until the algorithm is made.

7

INPUT is sugar required

IF (sugar is required)

THEN OUTPUT add sugar

ELSE

OUTPUT don’t add sugar

ENDIF

8 of 8

Loops

8

WHILE answer != “computer”

answer = INPUT what is the password

ENDWHILE

FOR i=0 to 7

OUTPUT “hello”

i++ #increase i by 1

ENDFOR

The image shows an example of a FOR LOOP and a WHILE LOOP.

The big difference to note is we first must declare the end of the loop.

Secondly we must manually increase values such as i as not all program languages does this step for us.