if)| Step | Score | Outer if (0 ≤ Score ≤ 100) |
Inner if (Score ≥ 70?) |
Grade |
|---|---|---|---|---|
| 1 | 85 | True | True | A |
| 2 | 62 | True | False | B |
| 3 | 38 | True | False | F |
| 4 | ‑5 | False | – | Invalid mark |
| Topic | Key Points to Cover |
|---|---|
| 1. Data Representation |
|
| 2. Data Transmission |
|
| 3. Hardware |
|
| 4. Software |
|
| 5. Data Management |
|
| 6. Ethical, Legal & Environmental Issues |
|
The remainder of these notes focuses on the programming side, especially nested statements, which are central to Topics 8 (Programming) and 9 (Databases).
| Concept | What you need to know | Example (Python) |
|---|---|---|
| Variables & data types | INTEGER, REAL, BOOLEAN, STRING, LIST/ARRAY | score = 0 # int |
| Input / output | INPUT / OUTPUT (or print) |
score = int(input("Enter mark: ")) |
| Operators | Arithmetic (+, –, *, /, //, %), Relational (=, ≠, <, >, ≤, ≥), Logical (and, or, not) | if score >= 70 and score <= 100: |
| Selection (if‑else) | Single, chained, and nested if |
See Section 4 |
| Iteration (loops) | while, for (count‑controlled and collection‑controlled) |
for i in range(1, 11): |
| String handling | Concatenation (+), slicing, length, conversion | msg = "Score: " + str(score) |
| Procedures / functions | Define once, call many times; may return a value | def grade_mark(m): |
| Libraries / modules | Import standard or user‑defined modules (e.g., import math) |
import random |
| Outer structure | Typical inner structures | Typical use |
|---|---|---|
if … else |
if … else inside either branch |
Multi‑level decision making |
while loop |
if … else or another while |
Repeated checks while a condition holds |
for loop |
if … else or another for |
Iterating over a collection with extra criteria |
# Python – indentation defines the block
if condition1:
# outer block
if condition2:
# inner block
statement
else:
# inner else
statement
else:
# outer else
statement
// Java – braces define the block
if (condition1) {
if (condition2) {
// inner block
statement;
} else {
// inner else
statement;
}
} else {
// outer else
statement;
}
# Pseudocode (Cambridge style)
IF condition1 THEN
IF condition2 THEN
statement
ELSE
statement
ENDIF
ELSE
statement
ENDIF
AND (·), OR (+), NOT (‾).if conditions.and/or, but the nested form is often clearer for beginners.| C₁ | C₂ | C₁ AND C₂ |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
Store a collection of values of the same type. Indexing starts at 0 in most languages (Python, Java, C#).
# Python – find the highest mark
marks = [78, 92, 65, 88, 73]
max_mark = marks[0] # initialise with first element
for i in range(1, len(marks)): # outer FOR over indices
if marks[i] > max_mark: # nested IF inside the FOR
max_mark = marks[i]
print("Highest mark is", max_mark)
// Java – search a seating chart for a free seat
int[][] seats = {
{0, 1, 0},
{1, 0, 0},
{0, 0, 1}
};
boolean free = false;
outer:
for (int r = 0; r < seats.length; r++) { // rows
for (int c = 0; c < seats[r].length; c++) { // columns
if (seats[r][c] == 0) { // nested IF
free = true;
break outer; // exit both loops
}
}
}
System.out.println(free ? "Seat available" : "Full");
File operations are always performed inside a loop, with nested if statements to test for end‑of‑file, errors, or specific content.
count = 0
try:
file = open("log.txt", "r") # open for reading
while True: # outer loop – read until break
line = file.readline()
if line == "": # inner IF – EOF
break
if "error" in line.lower(): # nested IF – keyword test
count += 1
finally:
file.close() # always close the file
print("Occurrences of ‘error’: ", count)
with (recommended)with open("data.txt", "r") as f:
for line in f: # outer FOR over lines
if line.strip() == "": # inner IF – ignore blanks
continue
if line.startswith("#"): # nested IF – comment line
print(line.rstrip())
CREATE TABLE Students (
StudentID INTEGER PRIMARY KEY,
Name VARCHAR(30),
Mark INTEGER
);
SELECT Name, Mark
FROM Students
WHERE Mark >= 70 -- outer condition: high achievers
AND Mark <= 100; -- inner condition: valid range
UPDATE Students
SET Grade = CASE
WHEN Mark >= 70 THEN 'A'
WHEN Mark >= 55 THEN 'B'
ELSE 'F'
END;
break inside a nested if when appropriate.break / continue – they affect only the innermost loop; use a flag variable or labelled break (Java) to exit multiple levels.finally block or, better, use a with statement (Python).if with a single expression.if & loopsn (0 < n < 100),n = int(input("Enter an integer (0‑99): "))
if 0 < n < 100:
is_prime = True
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
is_prime = False
break # exit inner loop
if is_prime:
print("Prime")
if n % 2 == 0:
print("Even")
else:
print("Odd")
else:
print("Composite")
else:
print("Number out of range")
IF x > 0 THEN
IF x < 5 THEN
PRINT "A"
ELSE
PRINT "B"
ENDIF
ELSE
PRINT "C"
ENDIF
x > 0 → True (enter outer IF).x < 5 → True (enter inner IF).if to a single Boolean expressionif 0 <= score <= 100 and score >= 70:
grade = "A"
elif 0 <= score <= 100:
grade = "B"
else:
grade = "Invalid mark"
Single expression version (Python):
grade = ("A" if 0 <= score <= 100 and score >= 70 else
"B" if 0 <= score <= 100 else
"Invalid mark")
Why the nested version is clearer:
SET count TO 0
FOR i FROM 0 TO LENGTH(marks)‑1 DO
IF marks[i] >= 70 THEN
SET count TO count + 1
ENDIF
ENDFOR
PRINT "Number of high marks =", count
with block that prints lines starting with “#” while ignoring blank lines:
with open("data.txt", "r") as f:
for line in f: # outer FOR over lines
if line.strip() == "": # inner IF – skip blanks
continue
if line.startswith("#"): # nested IF – comment line
print(line.rstrip())
if‑else chains.IF branching into two inner IF‑ELSE blocks (use standard Cambridge symbols).Create an account or Login to take a Quiz
Log in to suggest improvements to this note.
Your generous donation helps us continue providing free Cambridge IGCSE & A-Level resources, past papers, syllabus notes, revision questions, and high-quality online tutoring to students across Kenya.