KTU S1

What Pseudocode Is, and Why We Use It

By the end you should be able to: Define pseudocode, state the reasons for using it, and write simple pseudocode following standard conventions.

Pseudocode is a way of writing an algorithm using structured, English-like statements. It borrows the logic of a programming language without any language's syntax rules.

The name says it: pseudo (false) + code. It looks like code. It isn't code. No computer runs it.

Why bother, when you could just write Python?

This is the reasonable objection, and the syllabus explicitly asks for the "reasons for using pseudocode". There are five worth knowing.

1. It separates logic from syntax. When you write Python you must simultaneously get the thinking right and the punctuation right. Pseudocode lets you settle the thinking first. Most beginner bugs are logic errors dressed as syntax errors, and this separation prevents them.

2. It is language-independent. The same pseudocode can be handed to a Python programmer, a Java programmer and a C programmer, and all three will implement the same algorithm.

3. It is readable by non-programmers. A domain expert — an accountant, a civil engineer — can check whether your logic matches the real-world rule, without knowing any language.

4. It is quicker to write and change. Restructuring three lines of pseudocode takes seconds. Restructuring the equivalent code takes rather longer.

5. It documents intent. Six months later the pseudocode explains what the program was meant to do, which the code alone often doesn't.

The three constructs — and why only three

Every algorithm ever written can be expressed with just three control structures:

ConstructMeaning
SequenceDo this, then this, then this
SelectionIf a condition holds, do this; otherwise do that
RepetitionDo this repeatedly while a condition holds

This is the structured program theorem (Böhm–Jacopini). It is a genuinely remarkable result: three constructs suffice for everything a computer can compute. Every remaining topic in this module is one of these three.

Conventions

Pseudocode has no official standard, but conventions are widely shared and examiners expect them:

  • Capitalise keywords: IF, ELSE, WHILE, FOR, READ, PRINT
  • Indent to show what belongs inside what
  • Close blocks explicitly: ENDIF, ENDWHILE, ENDFOR
  • One action per line
  • Use ← or = for assignment — be consistent
  • Start with BEGIN, end with END

Example:

BEGIN
    READ radius
    area ← 3.14159 * radius * radius
    PRINT "Area is", area
END

What pseudocode is not

  • Not code. Don't write printf or System.out.println — that's committing to a language.
  • Not prose. "Work out the area somehow" is not pseudocode; it fails definiteness.
  • Not a flowchart. Same information, different notation. You'll meet flowcharts later in this module.

The right level of detail is: precise enough that any competent programmer would produce the same program from it.