← Back to subjects
0
Cambridge IGCSE Computer Science (0478) · Programming
Mini-Lesson

Programming

Programming turns an algorithm into code. Using Cambridge pseudocode, this mini-lesson covers data types, variables & constants, sequence, selection & iteration, operators, 1D & 2D arrays, procedures & functions, string handling and file handling.

sequence selection iteration

Work through each screen, answer the questions, and collect ⭐ stars. Press Start when ready.

Data types, variables & constants

Data types, variables & constants

Cambridge pseudocode uses these data types:

  • INTEGER — a whole number (e.g. 42).
  • REAL — a number with a decimal part (e.g. 3.14).
  • CHAR — a single character (e.g. 'A').
  • STRING — text (e.g. "hello").
  • BOOLEAN — TRUE or FALSE.

A variable holds a value that can change; a constant holds a value fixed for the whole program (e.g. CONSTANT Pi = 3.14). Assignment uses the arrow: Count ← 0.

Sort it

Which data type?

Tap a statement, then tap the data type it describes.

🔢 INTEGER

➗ REAL

🔤 CHAR

Operators

Operators

Arithmetic: + − * / plus DIV (whole-number division) and MOD (remainder). Comparison: = , <> (not equal), < , > , <= , >= . Logical: AND, OR, NOT.

Worked example — DIV and MOD

17 DIV 5 = 3 (how many whole 5s fit in 17).

17 MOD 5 = 2 (the remainder left over).

Calculate

Your turn — MOD

1What is the value of 23 MOD 4?
Hint: 4 × 5 = 20, so 23 leaves a remainder of 23 − 20.
Selection & iteration

Selection & iteration

Selection chooses a path: IF condition THEN … ELSE … ENDIF, or CASE OF for many options.

Iteration repeats code:

  • FOR count ← 1 TO 10 … NEXT count — a count-controlled loop (known number of repeats).
  • WHILE condition DO … ENDWHILE — repeats while a condition is true (checked before each pass).
  • REPEAT … UNTIL condition — repeats until a condition becomes true (checked after, so it always runs at least once).
Match it

Match the construct to its job

Tap a description on the left, then its matching construct on the right.

Description
Construct
Calculate

Your turn — trace a loop

2Trace this: x ← 1. WHILE x < 10 DO x ← x + 3 ENDWHILE. How many times does the loop body run?
Hint: x goes 1→4→7→10. It stops when x is no longer less than 10.
Arrays (1D & 2D)

Arrays

An array stores many values of the same type under one name, reached by an index. A 1D array is a list; a 2D array is a table (rows and columns).

1D array example

DECLARE Scores : ARRAY[1:4] OF INTEGER

Scores[1] ← 4, Scores[2] ← 8, Scores[3] ← 15, Scores[4] ← 16.

Total of all four = 4 + 8 + 15 + 16 = 43.

2D array: DECLARE Grid : ARRAY[1:3, 1:2] OF INTEGER gives 3 rows × 2 columns; Grid[2,1] is row 2, column 1.

Calculate

Your turn — array total

3An array holds Nums[1]=5, Nums[2]=10, Nums[3]=2, Nums[4]=8. A loop adds every element to a variable Total (starting at 0). What is the final Total?
Hint: 5 + 10 + 2 + 8.
Quick check

Array indexing

?For a 2D array declared ARRAY[1:3, 1:2], how many elements can it hold in total?
Procedures & functions

Procedures & functions

Both are named blocks of reusable code (subroutines) that can take parameters:

  • Procedure — carries out a task but does not return a value. Called with CALL (e.g. CALL DrawLine).
  • Function — carries out a task and returns a value (uses RETURN), so it can be used inside an expression (e.g. area ← Square(5)).

Why use them? They avoid repeating code, make programs easier to read and test, and let one block be reused many times.

Quick check

Procedure or function?

?Which is the key difference between a function and a procedure?
String & file handling

String & file handling

String handling functions in Cambridge pseudocode include LENGTH(s) (number of characters), SUBSTRING(s, start, length), UCASE(s) / LCASE(s) and joining strings with &.

Worked example

LENGTH("COMPUTER") = 8. UCASE("cat") = "CAT".

File handling stores data permanently. You OPEN a file for reading or writing, READFILE / WRITEFILE to move data, and CLOSEFILE when finished. EOF(file) tests for the end of the file.

Quick check

String length

?What does LENGTH("HELLO") return?
Quick check

File handling

?In pseudocode, which command should be used after finishing with a file to release it properly?
Quick check

Choosing a loop

?You must run a block of code exactly 10 times, a known number of repeats. Which loop is most suitable?
Recap

The big ideas to know

Data types: INTEGER, REAL, CHAR, STRING, BOOLEAN · variables change, constants don’t

Operators: +−*/, DIV, MOD, comparison, AND/OR/NOT

Constructs: sequence · selection (IF/CASE) · iteration (FOR, WHILE, REPEAT)

Arrays: 1D list & 2D table, reached by index

Subroutines: procedure (no return) vs function (returns a value)

Strings: LENGTH, SUBSTRING, UCASE · files: OPEN, READ/WRITE, CLOSE, EOF

You’ve covered the whole of Programming. Press Finish to see your score.

🏆

Mini-lesson complete!

⭐⭐⭐

You’ve worked through Programming for Cambridge IGCSE Computer Science. 🎉

Your stars: 0 / 0

Next: test yourself in the Evaluate stage Confidence Quiz, then lock it in with Verify.

📣 Smashed it? Share your score

Challenge a mate to beat your stars, or show a parent how you got on.

→ Back to all subjects