Define and use procedures and functions (with or without parameters) and integrate them with variables, I/O, control structures, totalling, counting, searching, sorting, and the broader concepts required by the Cambridge IGCSE syllabus.
| System | Base | Digits Used | Typical Use in CS |
|---|---|---|---|
| Binary | 2 | 0, 1 | Machine language, bit‑wise operations |
| Octal | 8 | 0‑7 | Compact representation of binary groups |
| Hexadecimal | 16 | 0‑9, A‑F | Memory addresses, colour codes |
| Decimal | 10 | 0‑9 | Human‑readable numbers |
Conversions (pseudocode)
FUNCTION BinToDec(binString)
BEGIN
DECLARE result, i, digit : INTEGER
result ← 0
FOR i ← 1 TO LENGTH(binString) DO
digit ← CHAR_TO_INT(binString[i]) // '0'→0, '1'→1
result ← result * 2 + digit
END FOR
RETURN result
END FUNCTION
IF (COUNT_OF_1s(data) MOD 2) = parityBit THEN
// no error
ELSE
// error detected
END IF
protocol://domain[:port]/path?query#fragmentTotalScore).DECLARE identifier : typeCONSTANT identifier ← valueTotalScore).| Command | Purpose | Example |
|---|---|---|
INPUT identifier |
Read a value from the user and store it in a variable. | INPUT Age |
OUTPUT expression(s) |
Display text or the value of an expression. | OUTPUT "Your age is ", Age |
| Structure | Syntax (pseudocode) | Typical Use |
|---|---|---|
| Sequence | Statements are executed one after another. | Simple processing steps. |
| Selection – IF |
IF condition THENstatements ELSEstatements END IF
|
Choose between two alternatives. |
| Selection – CASE |
CASE expression OFvalue1: …value2: …OTHER: …END CASE
|
Multiple‑choice selection. |
| Iteration – FOR |
FOR counter ← start TO end STEP step DOstatements END FOR
|
Known number of repetitions. |
| Iteration – WHILE |
WHILE condition DOstatements END WHILE
|
Repeat while a condition remains true. |
| Iteration – REPEAT … UNTIL |
REPEATstatements UNTIL condition
|
Execute at least once, then test. |
| Aspect | Procedure | Function |
|---|---|---|
| Purpose | Performs an action (e.g., display, update data) | Computes a value |
| Return value | None (void) | Exactly one value of a defined type |
| Typical use | Displaying results, changing global structures | Mathematical calculations, data transformation |
| Call syntax | CALL ProcedureName(arg1, arg2) | result ← FunctionName(arg1, arg2) |
| Parameter passing | By value or by reference (language‑dependent) | Usually by value; some languages allow reference parameters |
Parameters and variables declared inside a procedure or function are local. Their scope begins at the start of the routine and ends when the routine terminates. Global variables (declared outside any routine) remain accessible throughout the program.
PROCEDURE ShowWelcomeMessage()
BEGIN
OUTPUT "Welcome to the IGCSE Computer Science exam!"
END PROCEDURE
PROCEDURE PrintSum(a, b)
BEGIN
DECLARE sum : INTEGER
sum ← a + b
OUTPUT "The sum is ", sum
END PROCEDURE
PROCEDURE IncrementByOne(REF number)
BEGIN
number ← number + 1
END PROCEDURE
FUNCTION GetCurrentYear()
BEGIN
RETURN 2025 // static example; in real code you would query the system clock
END FUNCTION
FUNCTION Square(x)
BEGIN
RETURN x * x
END FUNCTION
area ← PI * Square(radius)
PROCEDURE TotalAndCount(numbers[])
BEGIN
DECLARE total, count, i : INTEGER
total ← 0
count ← 0
FOR i ← 1 TO LENGTH(numbers) DO
total ← total + numbers[i]
count ← count + 1
END FOR
OUTPUT "Total = ", total, ", Count = ", count
END PROCEDURE
PROCEDURE LinearSearch(data[], key)
BEGIN
DECLARE i, position : INTEGER
position ← 0 // 0 = not found
FOR i ← 1 TO LENGTH(data) DO
IF data[i] = key THEN
position ← i
EXIT FOR // stop as soon as it is found
END IF
END FOR
IF position = 0 THEN
OUTPUT "Key not present"
ELSE
OUTPUT "Key found at position ", position
END IF
END PROCEDURE
FUNCTION BubbleSort(list[])
BEGIN
DECLARE n, i, j, temp : INTEGER
n ← LENGTH(list)
FOR i ← 1 TO n-1 DO
FOR j ← 1 TO n-i DO
IF list[j] > list[j+1] THEN
temp ← list[j]
list[j] ← list[j+1]
list[j+1] ← temp
END IF
END FOR
END FOR
RETURN list
END FUNCTION
Students| StudentID (PK) | Name | Age | Score |
|---|---|---|---|
| 1001 | Alice | 14 | 78 |
| 1002 | Bob | 15 | 85 |
| 1003 | Carol | 14 | 92 |
SELECT Name, Score FROM Students WHERE Age = 14 ORDER BY Score DESC;
SELECT COUNT(*) AS NumStudents, SUM(Score) AS TotalScore FROM Students;
INSERT INTO Students (StudentID, Name, Age, Score) VALUES (1004, 'Dave', 15, 88);
UPDATE Students SET Score = Score + 5 WHERE StudentID = 1002;
DELETE FROM Students WHERE StudentID = 1003;
| Gate | Symbol | Truth Table |
|---|---|---|
| AND | ![]() |
A B | A∧B 0 0 | 0 0 1 | 0 1 0 | 0 1 1 | 1 |
| OR | ![]() |
A B | A∨B 0 0 | 0 0 1 | 1 1 0 | 1 1 1 | 1 |
| NOT | ![]() |
A | ¬A 0 | 1 1 | 0 |
| NAND | ![]() |
A B | ¬(A∧B) 0 0 | 1 0 1 | 1 1 0 | 1 1 1 | 0 |
| NOR | ![]() |
A B | ¬(A∨B) 0 0 | 1 0 1 | 0 1 0 | 0 1 1 | 0 |
| XOR | ![]() |
A B | A⊕B 0 0 | 0 0 1 | 1 1 0 | 1 1 1 | 0 |
AND – both conditions true.OR – at least one condition true.NOT – negates a condition.IF (age >= 18) AND (hasID = TRUE) THEN
OUTPUT "Access granted"
ELSE
OUTPUT "Access denied"
END IF
FUNCTION ConvertCtoF(celsius)
BEGIN
RETURN (celsius * 9/5) + 32
END FUNCTION
PROCEDURE DisplayAndStore(tempC)
BEGIN
DECLARE tempF : REAL
tempF ← ConvertCtoF(tempC)
OUTPUT tempC, "°C = ", tempF, "°F"
// Store the conversion in a simple table (pseudo‑SQL)
CALL ExecuteSQL("INSERT INTO Conversions (Celsius, Fahrenheit) VALUES (" &
tempC & ", " & tempF & ");")
END PROCEDURE
CALL DisplayAndStore(25)
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.