Consider this pseudocode: x = 5 / IF x > 3: print('A') / print('B'). What gets printed when this runs?
AOnly 'A' — the if-statement skips 'B' once its condition is satisfied
BOnly 'B' — branching replaces the default sequence
CBoth 'A' then 'B' — the branch executes its block, then execution continues sequentially
DNothing — conditional statements don't produce output without an else clause
Selection (branching) does not interrupt the overall sequential flow — it only decides whether the branch block runs. After the if-block executes (printing 'A'), execution resumes at the next statement in sequence (printing 'B'). A common misconception is that a branch terminates the program or permanently redirects execution, but control simply returns to the sequential flow after the branch completes.
Question 2 Multiple Choice
A loop is set up to print 'Hello' while a counter is less than 3, starting at 0 and incrementing by 1 each time. How many times does 'Hello' print?
A2 — the loop runs for values 0 and 1, and stops before reaching 3
B3 — the loop runs for values 0, 1, and 2
C4 — the loop runs for values 0, 1, 2, and 3 before the condition fails
D1 — the loop body only executes once per control flow structure
Tracing the execution: counter=0 (0 < 3, print), counter=1 (1 < 3, print), counter=2 (2 < 3, print), counter=3 (3 < 3 is false, stop). That's 3 executions for counter values 0, 1, and 2. Off-by-one errors are among the most common bugs, and they result from not tracing carefully: the loop condition is checked at value 3 (which fails), so the body runs for 0, 1, and 2 — three times total.
Question 3 True / False
If a statement appears earlier in the source code file, it will generally execute before a statement that appears later in the file.
TTrue
FFalse
Answer: False
Written order and execution order are not the same. A branch might skip over an entire block of code, meaning statements later in the file execute while statements earlier in the file do not. A loop might cause earlier statements (inside the loop body) to execute many more times than a single later statement. The key skill in debugging is tracing the actual execution path rather than reading the file linearly like prose.
Question 4 True / False
A program with no conditional statements and no loops will always produce the same output when run with the same input.
TTrue
FFalse
Answer: True
Without selection or iteration, a program is pure sequence — it executes every statement exactly once, in the same top-to-bottom order, every time. There is no branching to take a different path and no looping to repeat or skip. Given identical inputs and a fixed sequence of operations, the output is fully deterministic. This is actually useful to understand: it shows that branches and loops are what give programs their power to respond to varying conditions.
Question 5 Short Answer
Why is the written order of statements in source code not always the order in which they execute?
Think about your answer, then reveal below.
Model answer: Because control flow — branching and looping — can cause the computer to skip blocks of code (selection) or revisit blocks multiple times (iteration). A branch might mean a whole section of code never runs during a particular execution. A loop might mean the same block runs hundreds of times before the program moves on. The written code describes possibilities; the execution order depends on runtime conditions.
This is the key insight that separates reading code from understanding it. Novice programmers often read source code like a recipe (top to bottom, once through) and are surprised when a program doesn't behave as expected. The mental model shift — from 'what is written' to 'what the computer does' — is foundational. Tracing execution by hand, following the actual control flow rather than the file layout, is the technique that makes this concrete.