# Programming fundamentals

> CIE A-Level Computer Science · 9618
> Source: https://www.owlsprep.com/study/cie-9618-u11-programming-fundamentals/

This sub-topic introduces core terminology, structure, and key concepts that underpin all programming for CIE 9618 A-Level. You will learn key distinctions regularly tested in both Paper 1 and Paper 2 assessments.

**Prerequisites:** Basic logical reasoning and problem solving skills

## Learning objectives

- Distinguish between compilers and interpreters
- Identify the three core structured programming constructs
- Differentiate between syntax and semantic (logic) errors
- Compare imperative and declarative programming paradigms
- Answer common multiple-choice and short-answer exam questions on core programming concepts

## Core Translator Terminology

All high-level code must be translated to machine code that a computer can execute. The two most common types of translator tested in CIE 9618 are compilers and interpreters, and their differences are a frequent exam topic.

**Compiler** — A translator that processes the entire source code program in one go, producing a standalone executable machine code file that can be run independently later.

*Example:* A C compiler used to build desktop production software.

**Interpreter** — A translator that processes source code line-by-line during execution, translating one line at a time and does not produce a permanent executable file.

*Example:* An online Python editor that runs code as you type.

> **tip**
>
> CIE examiners always expect you to identify the key difference in when translation occurs: compilers translate *before* execution, interpreters translate *during* execution.

**Worked example:** State one advantage of using a compiler over an interpreter for commercial software.

1. Recall that compilers complete translation once, before any execution.
2. Executables produced by compilers run directly on the CPU with no further translation needed.
3. Write the answer: Compiled software runs faster than interpreted software because translation only happens once, rather than every time the program is launched.

## Core Structured Programming Constructs

All structured programs are built from just three core control constructs, regardless of the programming language used. Structured programming avoids messy unstructured jumps (like `goto` statements) and makes code easier to read and debug.

1. **Sequence**: Code executes in exactly the order it is written, line by line.
2. **Selection**: The program chooses between different blocks of code based on a boolean condition (e.g. `if`/`else`, `switch` statements).
3. **Iteration**: A block of code is repeated multiple times (also called looping, e.g. `for` and `while` loops).

**Worked example:** What type of core construct is shown in the pseudocode below?
```
FOR count FROM 1 TO 10
  OUTPUT count * count
NEXT count
```

1. Check if the code runs line-by-line with no choices or repetition: that is sequence, so this is not the case.
2. Check if the code chooses between code paths based on a condition: that is selection, which does not happen here.
3. Check if the code repeats a block multiple times: the `FOR` loop repeats the output line 10 times.
4. Conclusion: This is an example of iteration.

## Syntax vs Semantic (Logic) Errors

A very common exam question asks you to distinguish between two broad types of error in code. The difference between them is consistently tested in multiple-choice and short-answer questions.

**Syntax Error** — An error that violates the grammatical rules of the programming language. The translator cannot process the code, so the program will not run at all.

**Logic (Semantic) Error** — An error where the code follows all language rules (so no syntax error) and runs, but produces the wrong output because the underlying logic of the program is incorrect.

**Worked example:** The code below is intended to output `Positive` if the input number is greater than zero, and `Non-positive` otherwise. What type of error does it contain?
```
INPUT number
IF number < 0 THEN
  OUTPUT "Positive"
ELSE
  OUTPUT "Non-positive"
ENDIF
```

1. First check for syntax violations: all keywords are spelled correctly, the `IF` block is properly formatted, so the code will run.
2. Test with a sample input: input `5` (which is positive). The condition `5 < 0` is false, so the code outputs `Non-positive`, which is wrong.
3. The code runs, but produces the wrong result, so this is a logic (semantic) error.

## Introduction to Programming Paradigms

A programming paradigm is a style or approach to programming. CIE 9618 requires you to distinguish between the two most common paradigms: imperative (procedural) and declarative.

- **Imperative**: Code describes *how* to solve a problem, as a sequence of steps that change program state. Most general-purpose languages like Python, Java and C are imperative.
- **Declarative**: Code describes *what* result you want, not how to get it. The interpreter works out the steps to produce the result. SQL and HTML are common examples of declarative languages.

**Worked example:** Classify the following code as imperative or declarative: `SELECT product FROM stock WHERE price > 100;`

1. Check what the code describes: it states that we want the names of products with price over 100. It does not explain how to search the stock table for these products.
2. Recall that declarative code describes what result is needed, not how to get it.
3. Conclusion: This is an example of declarative code.

## Common pitfalls

- **Wrong:** Claiming interpreters produce executable machine code files.
  - Why it fails: This is the most common mistake on this topic, and examiners explicitly test this distinction.
  - Correct: Only compilers produce standalone executable machine code; interpreters translate line-by-line during execution and do not save a permanent executable.
- **Wrong:** Calling fixed named values variables.
  - Why it fails: The definition of a variable requires it to be able to change value during execution, fixed values are constants.
  - Correct: Use the term variable only for mutable named storage; fixed values are called constants.
- **Wrong:** Assuming all runtime errors are syntax errors.
  - Why it fails: Students often group all errors that stop execution together, but CIE distinguishes error types by their cause.
  - Correct: Syntax errors are caused by broken language rules; runtime errors (like dividing by zero) occur during execution of valid syntax.
- **Wrong:** Mixing up selection and iteration in classification questions.
  - Why it fails: Students often confuse the two constructs in short answer responses.
  - Correct: Selection = choice between paths, iteration = repetition of a code block.
- **Wrong:** Claiming a language can only belong to one paradigm.
  - Why it fails: Many modern languages support multiple paradigms, so classification depends on how the code is written.
  - Correct: Classify based on the code example: a step-by-step Python program is imperative, even though Python supports other paradigms.

## Cheatsheet

| Term | Key Definition |
| --- | --- |
| Compiler | Translates full source code once, produces executable |
| Interpreter | Translates line-by-line during execution |
| Variable | Named mutable memory storage |
| Constant | Named fixed memory storage |
| Syntax error | Rule violation, prevents program running |
| Logic error | Program runs, outputs wrong result |
| Sequence | Code executes in written order |
| Selection | Chooses code block by condition |
| Iteration | Repeats code block multiple times |
| Imperative | Tells computer *how* to solve problem |
| Declarative | Tells computer *what* result to get |

## What's next

Programming fundamentals are the bedrock of all programming work in CIE 9618. Every concept you learned here will be applied repeatedly when you write code, debug problems, and answer exam questions. Core distinctions like compiler vs interpreter and syntax vs logic error are regular topics in Paper 1 multiple-choice, so make sure you memorize these definitions before moving on. Next, you will build on these fundamentals to learn about data types, more advanced control structures, and debugging techniques that you will use for your practical programming work.

- [Control flow structures](https://www.owlsprep.com/study/cie-9618-u11-control-flow-structures/)
- [Procedures, Functions and Parameters](https://www.owlsprep.com/study/cie-9618-u11-procedures-functions-and-parameters/)
- [File Handling](https://www.owlsprep.com/study/cie-9618-u11-file-handling/)

---

From [OwlsPrep](https://www.owlsprep.com) — free study guides for A-Level, IB, AP and IGCSE, written against the official syllabus. Canonical page: https://www.owlsprep.com/study/cie-9618-u11-programming-fundamentals/
