Week 4 – Flow control Part 1: Selection
Completion requirements
This session explains how programs make decisions. It starts with a short history of control flow: plain sequencing, GOTO and the tangled code it produced, then structured programming and its three basic structures (sequence, selection, iteration). The main part covers selection: if, if/else, the else if ladder, switch and the ternary operator. Examples are given in pseudocode, C and Python. Students then work with Boolean expressions, relational and logical operators, and truth tables, and compare nested ifs with combined conditions. The course part ends with common C pitfalls: = vs ==, the dangling else, the stray semicolon, chained comparisons and lazy evaluation.