Programs decide what to do and repeat work using control structures. This unit covers sequence (running instructions in the right order), selection (making decisions with if statements) and iteration (repeating code with while and for loops), including when to choose one loop over the other. This is core B2.3 material for both SL and HL, so there is no HL-only content here. Trace the code examples yourself to check the outputs.
Slide 1 / 4
Sequence: order matters
Sequence means the instructions run one after another, in the order they are written.
Like following a recipe, the wrong order can produce a result that does not work.
Poor sequencing can cause errors such as infinite loops, deadlocks or incorrect inputs.
An infinite loop happens when a loop's end condition is never met, for example when a counter is never changed.
Check you've got it
0/4
1. Which programming construct is used to make a decision about which code to run next?
2. You want to keep asking a user for a password until they type it correctly, and you do not know how many attempts they will need. Which loop is most appropriate?
3. What is the output of this Python loop? for i in range(0, 5): print(i * 2)
4. Using this logic, what is printed when myAge is 12? if myAge <= 5: 'soft play centre'; elif myAge > 5 and myAge <= 12: 'the park'; elif myAge > 12 and myAge <= 18: 'meet friends'; else: 'the movies'
Free revision content. Multiple-choice answers are marked instantly. Written answers are marked by AI on /free-mark.