HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
Pseudocode, Trace Tables and Testing
  1. 1Writing pseudocode
  2. 2Trace tables and dry runs
  3. 3Test data and finding errors
  1. Computer Science
  2. /Pseudocode, Trace Tables and Testing
  3. /Writing pseudocode

Course 7.2·Lesson 1 of 3

Writing pseudocode

Pseudocode writes an algorithm in a precise, readable form that is not tied to one programming language. You learn the exam style of Cambridge IGCSE pseudocode: assignment with an arrow, INPUT and OUTPUT, IF and CASE, the three kinds of loop, MOD and DIV, and how to state the purpose of an algorithm and amend one.

about 25 min1 simulation1 practice question
Lesson 1 of 3Show all lessonsHide
Pseudocode, Trace Tables and Testing
  1. 1Writing pseudocode
  2. 2Trace tables and dry runs
  3. 3Test data and finding errors

Try the code and the simulations beside the lesson.

A plan any programmer can read

A recipe says "beat the eggs", not "move the fork in a circle 40 times". It is precise enough to follow, but not tied to one kitchen. Pseudocode is a recipe for a computer. It is precise, it reads like a program, and it does not belong to any one programming language.

In Paper 2 of Cambridge IGCSE Computer Science, questions show algorithms in one fixed style of pseudocode. You must read it and write it. The syllabus says precision is required: x > y is accepted, but "x is greater than y" is not. This lesson teaches the parts you need for algorithms. The next chapter, Programming in Pseudocode and Python, goes further with procedures, functions, arrays and files.

The rules of the style

  • Keywords are in capital letters: IF, WHILE, OUTPUT.
  • Names (identifiers) are in mixed case, with a capital letter for each new word: NumberOfPlayers, Total. They use only letters and digits and start with a capital letter.
  • Assignment uses an arrow: Total ← 0 means "Total takes the value 0".
  • Indentation is four spaces for the lines inside a statement. THEN and ELSE are indented by only two spaces.
  • Comments start with // and go to the end of the line.

Input, output and calculation

pseudocode
OUTPUT "Enter the length and the width"
INPUT Length
INPUT Width
Area ← Length * Width
OUTPUT "Area: ", Area

OUTPUT can show several values separated by commas. Here it shows a message and then the value of Area. The arithmetic operators are +, -, *, / and ^ (a power). Two more work on whole numbers.

  • DIV(17, 5) returns 333: the whole number of times 555 goes into 171717.
  • MOD(17, 5) returns 222: the remainder.

The comparison operators are =, <, <=, >, >= and <>. The last one means "not equal to". The logical operators are AND, OR and NOT.

Selection: IF and CASE

An IF statement chooses between two paths. Notice the layout: the condition on the IF line, then THEN and ELSE on their own lines, two spaces in.

pseudocode
IF Temp > 30
  THEN
    OUTPUT "Hot"
  ELSE
    OUTPUT "Mild"
ENDIF

A CASE statement chooses one of several paths by the value of a variable. The cases are tested in order. OTHERWISE is used when no case matches.

pseudocode
INPUT Move
CASE OF Move
  'L' : Position ← Position - 1
  'R' : Position ← Position + 1
  OTHERWISE OUTPUT "Use L or R"
ENDCASE

Iteration: three kinds of loop

  • Count-controlled: FOR ... TO ... NEXT runs a fixed number of times. STEP changes the amount added each time, and it can be negative.
  • Pre-condition: WHILE ... DO ... ENDWHILE tests the condition before each pass. It may not run at all.
  • Post-condition: REPEAT ... UNTIL tests the condition after each pass. It always runs at least once.
pseudocode
INPUT Table
FOR Count ← 1 TO 5
    OUTPUT Count, " x ", Table, " = ", Count * Table
NEXT Count

With the input 777 this outputs five lines, from 1 x 7 = 7 to 5 x 7 = 35. Here is a WHILE loop. It is the example the syllabus itself gives.

pseudocode
INPUT Number
WHILE Number > 9 DO
    Number ← Number - 9
ENDWHILE
OUTPUT Number

State the purpose, and amend an algorithm

To state the purpose of an algorithm, run it in your head with a few inputs and look at the pattern. The WHILE loop above takes 999 away until 999 or less is left. For 404040 it outputs 444, because 40−9−9−9−9=440 - 9 - 9 - 9 - 9 = 440−9−9−9−9=4. So its purpose is: "It outputs the remainder when the number is divided by 999, but gives 999 instead of 000."

To amend an algorithm, change only what the question asks, and keep the style. To make the times table run to 101010, change FOR Count ← 1 TO 5 to FOR Count ← 1 TO 10.

Practise with new numbers

Try it in Python

The grey blocks marked pseudocode are written in the exam style and do not run. The Python box is the same algorithm in Python, and that one runs. The Python below runs the times table and the WHILE loop. In Python, range(1, 6) gives the numbers 111 to 555, and MOD and DIV are written % and //. You met these in the Python Foundations book.

Read it first. Then run it. Compare each line with the pseudocode above.

1. Change number = 40 to number = 63. Predict the output first.

2. Change the loop to range(1, 11). Which pseudocode line would you amend to match?

Common mistakes

  • Writing = for assignment. In pseudocode, assignment is ←. The sign = is a comparison.
  • Words instead of operators. Write Score >= 50, not "Score is at least 50".
  • Forgetting the end keyword. Every IF needs ENDIF, every WHILE needs ENDWHILE, every FOR needs NEXT.
  • Mixing up MOD and DIV. MOD gives the remainder, DIV the whole-number part.
  • Choosing the wrong loop. A loop that must run at least once, such as asking for a password, suits REPEAT.

Remember these

  • Keywords in capitals, names in mixed case, ← for assignment, // for comments.
  • IF with THEN and ELSE, ending in ENDIF; CASE OF with OTHERWISE, ending in ENDCASE.
  • FOR is count-controlled, WHILE is pre-condition, REPEAT is post-condition.
  • MOD(a, b) is the remainder and DIV(a, b) the whole-number quotient.

Check yourself

Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.

  1. Write a pseudocode line that adds 111 to a variable called Score.
  1. What do DIV(29, 4) and MOD(29, 4) return?
  1. Which loop always runs its body at least once?
  1. What does FOR Number ← 10 TO 1 STEP -3 give Number each time?
  1. Amend this line so that it accepts any mark from 404040 upwards: IF Mark > 40.

References

  • Cambridge International, IGCSE Computer Science 0478 syllabus (2026, 2027 and 2028), unit 7, parts 3 and 9, and section 4: pseudocode.

Enroll free in Pseudocode, Trace Tables and Testing

Every lesson is open to read. Enrolling also lets you:

  • Mark lessons done and carry on where you stopped.
  • Count the course towards the certificate for its chapter.
No payment. You can leave at any time.

Problems (4)

A garden centre sells turf by the square metre…Easy · High School (9–10) · by StemPy Lab
A sports watch records the length of a run in minutes…Medium · High School (9–10) · by StemPy Lab
This algorithm outputs the even numbers from 2 to 12…Medium · High School (9–10) · by StemPy Lab
Next: lesson 2Trace tables and dry runs
← Pseudocode, Trace Tables and Testing
← PreviousTrace tables and dry runs →

Discussion (0)

Log in to join the discussion.

Loading…

1 Python program
5 questions to check yourself

This lesson is free to read. Enroll free to keep your place in the course.

This is the kind of long scenario question that ends Paper 2…
Hard · High School (9–10) · by StemPy Lab

Python Labs (1)

Pseudocode into PythonPython Lab · by StemPy Lab