B2.3 Programming constructs: notes and practice
B2.3 is the core of programming: sequence, selection with if and else, loops that count or check a condition, nested loops and functions with parameters and return values.
What you need to know
Our summary of the topic in our own words, not the IB guide.
- Write a program whose statements run in the correct order to meet a stated objective
- Write conditional statements using if, else if and else
- Write nested and compound conditions correctly
- Trace a program with branching and state which branch runs for given inputs
- Write a count-controlled loop
- Write a condition-controlled loop and avoid an infinite loop
- Write nested loops, for example to process a two-dimensional structure
- Trace a loop and state the number of iterations and the final values
- Define a function with parameters and a return value, and call it
- Explain the difference between a parameter and an argument, and between returning and printing
- Decompose a long program into functions and explain the benefit of modularisation
Learn it
- Print one line
Lesson with 2 exercises
- Statements run top to bottom
Lesson with 2 exercises
- Read a line and print it back
Lesson with 2 exercises
- Read several lines, use them in any order
Lesson with 2 exercises
- Capstone: several inputs, several results
Lesson with 1 exercise
- if
Lesson with 3 exercises
- else
Lesson with 3 exercises
- else-if chains; the first true branch wins
Lesson with 3 exercises
- Comparing text
Lesson with 2 exercises
- and, or, not
Lesson with 3 exercises
- Nested conditions
Lesson with 1 exercise
- Trace a branching program
Lesson with 2 exercises
- Capstone: several rules decide one answer
Lesson with 1 exercise
- Loop until a stop value
Lesson with 3 exercises
- Every loop needs an update; find the infinite loop
Lesson with 2 exercises
- The counting pattern
Lesson with 2 exercises
- Sum and average, with an empty-input guard
Lesson with 3 exercises
- Count-controlled loop
Lesson with 3 exercises
- Loop bounds from input; a running total over a range
Lesson with 2 exercises
- Nested loops
Lesson with 3 exercises
- Trace a loop: iterations and final values
Lesson with 3 exercises
- Capstone: read a stream, report several statistics
Lesson with 1 exercise
- Define and call a function
Lesson with 2 exercises
- Pass a value in
Lesson with 2 exercises
- Return a value
Lesson with 3 exercises
- Parameter versus argument; returning versus printing
Lesson with 4 exercises
- Several parameters; order matters
Lesson with 2 exercises
- Functions that call your functions
Lesson with 3 exercises
- Capstone: split a long program into functions
Lesson with 1 exercise
- Loop over the characters
Lesson with 5 exercises
Practice questions
Original questions written for the 2027 course, marked as you go. Easiest first.
- Cafe menuCoding · Warm-up
- Count until stopCoding · Warm-up
- Door messagesCoding · Warm-up
- Double a numberCoding · Warm-up
- Even or oddCoding · Warm-up
- First lineCoding · Warm-up
- Floor signCoding · Warm-up
- For vs whileWritten · Warm-up
- Function purposeWritten · Warm-up
- Greeting with a borderCoding · Warm-up
- ID cardCoding · Warm-up
- Is evenCoding · Warm-up
- Loop update ruleWritten · Warm-up
- Message boardCoding · Warm-up
- Old enoughCoding · Warm-up
- Param vs argWritten · Warm-up
- Password checkCoding · Warm-up
- Print starsCoding · Warm-up
- Range with andCoding · Warm-up
- Repeat a characterCoding · Warm-up
- Repeat messageCoding · Warm-up
- Show N timesCoding · Warm-up
- Star bannerCoding · Warm-up
- Swap linesCoding · Warm-up
- Trace: if ageTrace table · Warm-up
- Trace: if elseTrace table · Warm-up
- Absolute valueCoding · Core
- Average scoreCoding · Core
- Check temperatureCoding · Core
- Clamp a valueCoding · Core
- Command checkCoding · Core
- Custom borderCoding · Core
- Count the digitsCoding · Core
- Find infinite loopWritten · Core
- Grade letterCoding · Core
- Grid coordinatesCoding · Core
- Halving stepsCoding · Core
- Integer powerCoding · Core
- Lift distanceCoding · Core
- Largest of threeCoding · Core
- Login checkCoding · Core
- Pass markCoding · Core
- Range checkCoding · Core
- Sign checkCoding · Core
- Star rectangleCoding · Core
- Sum of digitsCoding · Core
- Sum a rangeCoding · Core
- Sum until zeroCoding · Core
- Ticket priceCoding · Core
- Times table rowCoding · Core
- Trace: and orTrace table · Core
- Trace: digit sumTrace table · Core
- Trace: elifTrace table · Core
- Trace: elif updateTrace table · Core
- Trace: gradesTrace table · Core
- Trace: nested gridTrace table · Core
- Trace: return valueTrace table · Core
- Trace: return value (Java)Trace table · Core
- Trace: step loopTrace table · Core
- Trace: sum loopTrace table · Core
- Trace: two ifsTrace table · Core
- Trace: while countdownTrace table · Core
- Weekend checkCoding · Core
- Why decomposeWritten · Core
- Grade reportCoding · Stretch
- Trace table: counting free cinema seatsTrace table · Stretch
- Pay slipCoding · Stretch
- Score reportCoding · Stretch
- Stream statisticsCoding · Stretch
- Trace: nested countTrace table · Stretch
Exam tips for B2.3
- Check loop boundaries carefully. Off-by-one errors are a very common mistake.
- Know the difference between returning a value and printing it.
- Break long answers into small functions. It is easier to write and to mark.
Updated 24 October 2026. Topic codes are used as labels. Everything on this page is written by ExamSpine and is not endorsed by the IB.