Introduction to Programming and Logic Building
This domain tests logic rather than any one language: whether you can convert a problem into ordered steps, draw or read a flowchart, trace a loop accurately, and name the type of error in a faulty program.
Core rules
- Algorithm: finite, ordered, unambiguous steps with a clear stop point. Pseudocode expresses the same logic in plain words.
- Flowchart symbols: oval = start/stop, parallelogram = input/output, rectangle = process, diamond = decision, arrow = flow direction, circle = connector.
- Three control structures: sequence, selection (if/else), iteration (for/while).
- Variables hold changing values, constants do not; data types decide which operations are legal.
- Operator precedence: parentheses → arithmetic (÷, ×, +, −) → comparison → logical.
- Error types: syntax (breaks the rules of the language), runtime (crashes while running, e.g. division by zero), logical (runs but gives the wrong answer).
- A compiler translates the whole program before running; an interpreter translates line by line.
Worked example
sum = 0; for i = 1 to 5: sum = sum + i. Trace: i=1 sum=1; i=2 sum=3; i=3 sum=6; i=4 sum=10; i=5 sum=15. Output 15. If the body were empty, the program would still run and print 0 - that is a logical error, not a syntax error. Reasoning: the loop executes exactly 5 times because the range is inclusive.
Traps that cost marks
- Writing = where a comparison == is required.
- Off-by-one loop counts (1 to 5 runs five times).
- Forgetting the increment, producing an infinite loop.
- Using the process rectangle for a decision.