Programming Concepts and Logic
Programming Concepts and Logic tests algorithms, flowcharts, variables, control structures and dry running simple code. You do not need a specific language, but you must follow logic precisely.
Core rules
- An algorithm is a finite ordered set of steps. A flowchart uses oval (start/end), parallelogram (input/output), rectangle (process), diamond (decision) and arrows (flow).
- A variable is a named storage location; its value can change. Constants do not change. Data types include integer, real, character, string and Boolean.
- Operators: arithmetic (+ − × ÷, modulus), relational (=, <, >, ≤, ≥, ≠) and logical (AND, OR, NOT). In many languages = assigns and == compares.
- Control structures: sequence (steps in order), selection (if/else, switch), iteration (for, while, do-while). A loop needs a condition that eventually becomes false.
- Dry running means tracing values line by line in a table.
Worked example
Find the larger of two numbers A and B. Algorithm: 1) Start. 2) Input A, B. 3) If A > B then print A, else print B. 4) Stop. Flowchart: start oval → input parallelogram → decision diamond 'A > B?' → Yes branch to output A, No branch to output B → end oval. If A=7 and B=12, the decision is false, so output 12. If A=B, the else branch prints B; to handle equality, add a second check.
Traps
- Writing an infinite loop with no change to the loop variable.
- Confusing assignment (=) with comparison (==).
- Reversing the Yes/No branches in a decision.
- Ignoring operator precedence; use brackets when unsure.
- Skipping the dry run, so off-by-one errors go unnoticed.