Programming Fundamentals and Logic
What the domain covers
Programming Fundamentals and Logic tests problem decomposition, algorithms, flowcharts, pseudocode, variables and data types, control structures, functions, arrays, Boolean logic, and debugging.
Core rules and concepts
- An algorithm is a finite, unambiguous sequence of steps. A flowchart uses standard symbols: oval for start/end, parallelogram for input/output, rectangle for process, diamond for decision.
- A variable is a named storage location whose value can change; a constant does not change during execution. Data types include integer, real, character, string, and Boolean.
- Control structures are sequence, selection (if/else, switch), and iteration (for, while, do-while).
- A for loop is used when the number of repetitions is known; a while loop tests before each iteration and may run zero times; a do-while tests after and runs at least once.
- Functions take parameters, perform a task, and may return a value. Arrays store multiple values of the same type under one name and are accessed by index.
- Boolean operators: NOT has highest precedence, then AND, then OR. Truth tables test all combinations.
Worked example
Pseudocode: sum ← 0 for i ← 1 to 3 sum ← sum + i print sum Trace: start sum=0. i=1: sum=1. i=2: sum=3. i=3: sum=6. Output 6. Reason: the loop body runs three times, and each iteration adds the current i to the running total. If the loop were to 4, the output would be 10. Tracing values on paper prevents off-by-one errors.
Traps that cost marks
= assigns; == compares in many languages. AND is not the same as OR; check precedence in mixed expressions. A loop whose condition never becomes false runs forever. Array indexes often start at 0, so the last index is length − 1. Declaring a variable does not always initialise it. Test boundary cases: zero, one, negative, and maximum.