Write clear, correct algorithms that use decision‑making (branching and looping), include procedures/sub‑routines, and represent them accurately with flowcharts. All structures must be presented using the Cambridge standard notation.
| Category | Operator | Meaning |
|---|---|---|
| Relational | > | greater than |
| Relational | < | less than |
| Relational | = | equal to |
| Relational | >= | greater than or equal to |
| Relational | <= | less than or equal to |
| Arithmetic | + | addition |
| Arithmetic | - | subtraction |
| Arithmetic | * | multiplication |
| Arithmetic | / | division |
| Logical | AND | both conditions true |
| Logical | OR | either condition true |
| Logical | NOT | negates a condition |
IF, THEN, ELSE, ENDIF, WHILE, DO, ENDWHILE, REPEAT, UNTIL, FOR, TO, STEP, ENDFOR, CASE, ENDCASE, PROCEDURE, FUNCTION, CALL, RETURN).//.RETURN) produce a result.| Symbol | Meaning |
|---|---|
| Oval | Start / End (terminator) |
| Parallelogram | Input / Output |
| Rectangle | Processing (assignment, calculation) |
| Diamond | Decision / Branching (condition tested) |
| Rounded rectangle | Sub‑routine (procedure or function) call |
| Connector (small circle) | Jump to another part of the diagram (used when a flowchart spans more than one page) |
| Arrows | Direction of flow; label with “Yes/No”, “True/False”, or a short description where a decision splits the flow. |
IF … ELSEIF … but clearer when testing a single variable.
FUNCTION AssignGrade(score) RETURNS CHAR
CASE score OF
90 TO 100: grade ← 'A'
80 TO 89 : grade ← 'B'
70 TO 79 : grade ← 'C'
60 TO 69 : grade ← 'D'
0 TO 59 : grade ← 'F'
ENDCASE
RETURN grade
ENDFUNCTION
Three loop structures are required by the syllabus. All use UPPERCASE keywords.
Loops may be placed inside other loops to handle two‑dimensional data such as tables, matrices, or grids.
PROCEDURE PrintTable(max)
FOR i ← 1 TO max DO
FOR j ← 1 TO max DO
OUTPUT i * j, " "
ENDFOR
OUTPUT NEWLINE
ENDFOR
ENDPROCEDURE
A procedure groups statements that perform a specific task but does not return a value. A function (or a procedure that uses RETURN) produces a result that can be used by the calling algorithm.
PROCEDURE ProcedureName(param1, param2, …)
// body of the procedure
ENDPROCEDURE
FUNCTION FunctionName(param1, param2, …) RETURNS datatype
// body of the function
RETURN result
ENDFUNCTION
CALL ProcedureName(arg1, arg2, …)
value ← CALL FunctionName(arg1, arg2, …)
FUNCTION CalcAverage(a, b, c) RETURNS REAL
sum ← a + b + c
avg ← sum / 3
RETURN avg
ENDFUNCTION
// Main algorithm
INPUT x, y, z
average ← CALL CalcAverage(x, y, z)
OUTPUT "Average =", average
FUNCTION Factorial(n) RETURNS INTEGER
result ← 1
counter ← n
WHILE counter > 0 DO
result ← result * counter
counter ← counter - 1
ENDWHILE
RETURN result
ENDFUNCTION
PROCEDURE SumUntilZero()
total ← 0
REPEAT
INPUT x
total ← total + x
UNTIL x = 0
OUTPUT "Total =", total
ENDPROCEDURE
PROCEDURE PrintEven(n)
FOR i ← 1 TO n DO
IF i MOD 2 = 0 THEN
OUTPUT i
ENDIF
ENDFOR
ENDPROCEDURE
FUNCTION MaxValue(list, size) RETURNS INTEGER
max ← list[1]
FOR i ← 2 TO size DO
IF list[i] > max THEN
max ← list[i]
ENDIF
ENDFOR
RETURN max
ENDFUNCTION
// Main
INPUT size
DECLARE numbers[ size ]
FOR i ← 1 TO size DO
INPUT numbers[i]
ENDFOR
big ← CALL MaxValue(numbers, size)
OUTPUT "Maximum =", big
FUNCTION Discount(age, member) RETURNS REAL
IF age < 18 THEN
IF member = TRUE THEN
discount ← 0.25 // 25 % for young members
ELSE
discount ← 0.10 // 10 % for non‑members
ENDIF
ELSE
CASE member OF
TRUE : discount ← 0.15
FALSE: discount ← 0.05
ENDCASE
ENDIF
RETURN discount
ENDFUNCTION
+-------------------+
| Start |
+-------------------+
|
v
+-------------------+
| Input n |
+-------------------+
|
v
+-------------------+
| result ← 1 |
| counter ← n |
+-------------------+
|
v
+-------------------+
| counter > 0 ? ----+--- No -->+-------------------+
| (Decision) | | Output result |
+-------------------+ +-------------------+
| Yes
v
+-------------------+
| result ← result*counter |
| counter ← counter-1 |
+-------------------+
|
+-------------------+
| (back to decision)
v
+-------------------+ +---------------------------+
| Start | | Procedure CalcAverage |
+-------------------+ +---------------------------+
| |
v |
+-------------------+ | INPUT a, b, c |
| INPUT x, y, z | | sum ← a+b+c |
+-------------------+ | avg ← sum/3 |
| | RETURN avg |
v +---------------------------+
+-------------------+ ^
| CALL CalcAverage |---------------------|
| (x,y,z) |
+-------------------+
|
v
+-------------------+
| OUTPUT avg |
+-------------------+
|
v
+-------------------+
| End |
+-------------------+
+-------------------+
| Start |
+-------------------+
|
v
+-------------------+
| INPUT max |
+-------------------+
|
v
+-------------------+
| i ← 1 |
+-------------------+
|
v
+-------------------+
| i ≤ max ? ----+--- No -->+-------------------+
| (Decision) | | End |
+-------------------+ +-------------------+
| Yes
v
+-------------------+
| j ← 1 |
+-------------------+
|
v
+-------------------+
| j ≤ max ? ----+--- No -->+-------------------+
| (Decision) | | i ← i + 1 |
+-------------------+ +-------------------+
| Yes
v
+-------------------+
| OUTPUT i*j, " " |
+-------------------+
|
v
+-------------------+
| j ← j + 1 |
+-------------------+
|
+-------------------+
| (back to j‑decision)
v
O(log n) instead of O(n)).Original linear search:
PROCEDURE LinearSearch(arr, n, key) RETURNS INTEGER
FOR i ← 1 TO n DO
IF arr[i] = key THEN
RETURN i
ENDIF
ENDFOR
RETURN 0 // not found
ENDPROCEDURE
Optimised binary search (array must be sorted):
FUNCTION BinarySearch(arr, n, key) RETURNS INTEGER
low ← 1
high ← n
WHILE low ≤ high DO
mid ← (low + high) DIV 2
IF arr[mid] = key THEN
RETURN mid
ELSEIF arr[mid] < key THEN
low ← mid + 1
ELSE
high ← mid - 1
ENDIF
ENDWHILE
RETURN 0 // not found
ENDFUNCTION
Students must spot both syntactic (keyword misspelling, missing END) and logical (wrong condition, off‑by‑one) errors.
PROCEDURE Sum_Until_Zero()
INPUT x
total ← 0
WHILE x ≠ 0 DO
total ← total + x
INPUT x
ENDWHILE
OUTPUT total
ENDPROCEDURE
REPEAT…UNTIL structure that guarantees at least one execution.
PROCEDURE Sum_Until_Zero()
total ← 0
REPEAT
INPUT x
total ← total + x
UNTIL x = 0
OUTPUT total
ENDPROCEDURE
PROCEDURE CheckAge(age)
IF age >= 18 THEN
OUTPUT "Adult"
ELSE
OUTPUT "Minor"
// ENDIF missing here
ENDPROCEDURE
ENDIF is omitted, causing a compilation‑style error.
PROCEDURE CheckAge(age)
IF age >= 18 THEN
OUTPUT "Adult"
ELSE
OUTPUT "Minor"
ENDIF
ENDPROCEDURE
PROCEDURE PrintNumbers(n)
FOR i ← 1 TO n DO
OUTPUT i
ENDFOR
OUTPUT "Done"
ENDPROCEDURE
0 to n inclusive. The loop starts at 1, omitting 0.
PROCEDURE PrintNumbers(n)
FOR i ← 0 TO n DO
OUTPUT i
ENDFOR
OUTPUT "Done"
ENDPROCEDURE
| Loop Type | When Condition Tested | Typical Use | Example Pseudocode |
|---|---|---|---|
| WHILE | Before each iteration (pre‑test) | When the number of repetitions is unknown and the loop may execute zero times. | WHILE count < limit DO
// body
ENDWHILE |
| REPEAT…UNTIL | After each iteration (post‑test) | When the loop must run at least once (e.g., menu selection, input validation). | REPEAT
// body
UNTIL choice = 0 |
| FOR…ENDFOR | Before each iteration (counter check) | When the exact number of repetitions is known in advance. | FOR i ← 1 TO 10 STEP 2 DO
// body
ENDFOR |
Mastering algorithms, decision‑making, and flowcharts provides the foundation for all subsequent Cambridge Computer Science units. In Data Structures (Topic 17) you will translate these algorithms into operations on lists, arrays, and trees. In Programming for the Web (Topic 21) the same logical structures are expressed in languages such as Python, JavaScript or PHP, where the pseudocode conventions become actual code. Understanding how to design, optimise, and debug an algorithm now will make the transition to real‑world programming far smoother.
Create an account or Login to take a Quiz
Log in to suggest improvements to this note.
Your generous donation helps us continue providing free Cambridge IGCSE & A-Level resources, past papers, syllabus notes, revision questions, and high-quality online tutoring to students across Kenya.