Pseudo Code

From TRCCompSci - AQA Computer Science
Jump to: navigation, search

Back To Basics...

Pseudocode is a simple way of writing programming code in English. Pseudocode is not actual a programming language. It uses short phrases to write code for programs before you actually create it in a specific language (i.e C++). Once you know what the program is about and how it will function, then you can use pseudocode to create statements to achieve the required results for your program.

Common Keywords For Pseudocode…

  • Input = indicates a user will be inputting something into the code
  • Output = indicates that there will be an output from the program
  • While = a loop (until a condition has been met)
  • For = a continuous loop
  • Repeat - Until = a loop that has a condition until the end
  • If - Then - Else = a decision in which a choice is made
  • Any other instruction that occurs inside a selection or iteration are usually indented

Examples - What Do They Do?

    Set total to zero
    Set grade counter to one
    While grade counter is < or equal to ten
    Input the next grade
    Add the grade into the total
    Set the class average to the total divided by ten
    Print the class average.
    OUTPUT ‘What is the best subject you take?’
    INPUT user inputs the best subject they take
    STORE the user’s input in the answer variable
    IF answer = ‘Computer Science’ THEN
         OUTPUT ‘Of course it is!’
         OUTPUT ‘Try again!’
    UNTIL answer = ‘Computer Science

When You Are Writing You Pseudocode, you have to take into consideration the following…

  • What are all of your inputs?
  • What are all of your outputs?
  • In what order does the code need to be carried out?
  • What decisions need to be made in the code?
  • Is there any area of the code that 
is repeated?

How To Tackle An Exam Question

Do It All In A Step By Step Basis..

* Think Logically...

  • What are my inputs, outputs and so on?
  • What is the question asking me?
  • What are the numbers? Are they integers? Is it an boolean?

Now It Is Your Turn…

Write you own pseudocode for anything that you want. If you are stuck here are a few ideas:

  • How to make a cheese toastie
  • How to get ready in the morning
  • How to warm up a ready meal

An Exam Question...

Pseudocode (2)-1.png