Programming Fundamentals and Logic
This domain tests algorithm properties, flowchart symbols, the three control structures, and dry-running small programs to predict output.
Algorithm and flowchart rules
A good algorithm is finite (terminates), definite (no ambiguous step), has zero or more inputs, at least one output, and is effective. Flowchart symbols: oval = start/stop, parallelogram = input/output, rectangle = process, diamond = decision with one entry and two exits, arrow = flow, circle = connector.
Control structures
Sequence, selection (if, if-else, nested if, switch) and iteration. while tests before the body and may run zero times; do-while tests after and runs at least once; for bundles initialisation, test and update. A counter increases by a fixed step; an accumulator adds changing values (sum = sum + x).
Worked example
Read n; sum ← 0; i ← 1; while i ≤ n: sum ← sum + i; i ← i + 1; print sum. Trace with n = 4: i=1 sum=1; i=2 sum=3; i=3 sum=6; i=4 sum=10; i=5 fails the test, so the output is 10. In trace questions most marks are for the table of values, not for the final number.
Swap logic
temp ← a; a ← b; b ← temp. The order matters - assigning a ← b first destroys a's original value.
Traps
- Using = for comparison instead of ==.
- Omitting i ← i + 1, producing an infinite loop and no output.
- Off-by-one: i < n instead of i ≤ n drops the last term.
- Leaving sum or i uninitialised, so a garbage value enters the result.
- Drawing a decision diamond with three outgoing arrows.