Pseudocode is a simple way of describing an algorithm that does not have to use specific syntaxThe set of rules that specify the correct sequence of symbols used to correctly form a structured program using specific programming language.. Pseudocode allows us to represent a program in programming-type statements.
If, for example, we want to check that an input value for age is sensible, pseudocode to do this could be written:
SEND "Please enter an age" TO DISPLAY
RECEIVE age FROM (INTEGER) KEYBOARD
WHILE age < 0 OR age > 130 DO SEND "Please enter a valid age between 0 and 130" TO DISPLAY RECEIVE age FROM (INTEGER) KEYBOARD
END WHILE
There is no set standard for pseudocode, however some of the most common are listed below:
INPUT – indicates a user will be inputting something.
OUTPUT – indicates that an output will appear on the screen.
WHILE – a loop (iteration that has a condition at the beginning that is repeated until the condition is met).
Example:
count = 1
Repeat WHILE count <7 Send "Hello" to Display
Count = count +1
FOR – a counting loop (iteration).
Example:
FOR number = 0 to 7 OUTPUT("Hello")
next number
Will print hello 8 times (0-7 inclusive).
IF – THEN – ELSE – a decision (selection) in which a choice is made.
Example:
if entry="a" then Send("You selected A") to Display
if entry="b" then Send ("You selected B")to Display else Send("Unrecognised selection") to Display
end