Representing algorithms
An algorithm is a sequence of steps that solves a problem. It can be written in several ways before it is coded.
Pseudo-code looks like a program but isn't in any real language, so it can be read by anyone and turned into any language. The style used here:
total = 0
for i = 1 to 10
input mark
if mark >= 50 then
total = total + 1
end if
next i
output totalExam papers use their own pseudo-code and explain any unusual parts. What matters is that each step is clear and unambiguous.
Flowcharts show an algorithm as a diagram:
| Symbol | Shape | Used for |
|---|---|---|
| Terminator | Rounded rectangle | Start and Stop |
| Process | Rectangle | A calculation or assignment |
| Decision | Diamond | A yes/no question, with two exits |
| Input/output | Parallelogram | Input or output |
| Subroutine | Rectangle with double sides | Calling a procedure or function |
| Flow line | Arrow | The order of the steps |
Structured English describes the steps in plain English, using a small set of words such as IF, THEN, ELSE, REPEAT, UNTIL, FOR EACH, with indentation to show structure. It is easiest for non-programmers to follow.
All three use the same three building blocks: sequence (steps in order), selection (if, case) and iteration (loops).