8.1 Programming

Declarations and Data Types

Storing Data

Programs need to store data in memory locations. We categorize these into two types:

  • Variables: The value can change during the program execution (e.g., a Score).
  • Constants: The value remains fixed throughout (e.g., PI = 3.142).

IGCSE Data Types:

  • INTEGER: Whole numbers (e.g., 10, -5).
  • REAL: Numbers with decimals (e.g., 15.5).
  • CHAR: A single character (e.g., "A").
  • STRING: Multiple characters (e.g., "Hello").
  • BOOLEAN: TRUE or FALSE.
Concept Diagram
Figure 8.1.1: Declarations and Data Types

Basic Constructs

Sequence and Selection

All programs are built using three main structures. The first two are:

  • Sequence: Statements are executed one after another in order.
  • Selection: The program takes different paths based on a condition (e.g., IF...THEN...ELSE or CASE).
Concept Diagram
Figure 8.1.2: Basic Constructs

Loops (Iteration)

Repeating Code

Cambridge focuses on three types of loops in pseudocode:

  1. FOR...TO...NEXT: Count-controlled (runs a set number of times).
  2. WHILE...DO...ENDWHILE: Pre-condition (checks the condition before running).
  3. REPEAT...UNTIL: Post-condition (runs at least once, checks after).
Examiner Insight: Ensure loops terminate correctly! Avoid "Infinite Loops" by updating your counter or condition variable.
Concept Diagram
Figure 8.1.3: Loops (Iteration)