Skip to main content
EnglandComputer ScienceSyllabus dot point

What are the three programming constructs, and how do you use selection and the two kinds of iteration?

The three basic programming constructs: sequence, selection (if and switch/case) and iteration (count-controlled for loops and condition-controlled while and do until loops), and when to use each.

An OCR J277 2.2.2 answer on the three programming constructs: sequence, selection (if and switch/case) and iteration (count-controlled for loops and condition-controlled while and do until loops), with the OCR Exam Reference Language for each.

Generated by Claude Opus 4.811 min answer

Reviewed by: AI editorial process; not yet individually human-reviewed

Have a quick question? Jump to the Q&A page

Jump to a section
  1. What this dot point is asking
  2. Sequence
  3. Selection
  4. Iteration
  5. Try this

What this dot point is asking

OCR wants you to use the three basic programming constructs: sequence, selection and iteration. You must know selection with if and with switch/case, and the two kinds of iteration (count-controlled for loops and condition-controlled while and do ... until loops), and choose the right one for a task. These constructs appear in almost every Paper 2 program.

Sequence

Selection

A grade example using if/elseif:

if mark >= 70 then
  print("Distinction")
elseif mark >= 50 then
  print("Merit")
elseif mark >= 40 then
  print("Pass")
else
  print("Fail")
endif

Iteration

Try this

Q1. Name the three basic programming constructs. [1 mark]

  • Cue. Sequence, selection and iteration.

Q2. State which kind of loop you would use to repeat a block exactly 20 times. [1 mark]

  • Cue. A count-controlled loop (a for loop).

Q3. State the difference between a while loop and a do ... until loop. [2 marks]

  • Cue. A while loop checks the condition before each pass, so it may run zero times; a do ... until loop checks after each pass, so it always runs at least once.

Exam-style practice questions

Practice questions written in the style of OCR exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.

OCR 20214 marksExplain the difference between a count-controlled loop and a condition-controlled loop, and give an example of when each would be the better choice.
Show worked answer →

Count-controlled loop (up to 2): repeats a fixed, known number of times, using a for loop with a start and end value. Example: printing the 12 rows of a times table, where you know there are exactly 12.

Condition-controlled loop (up to 2): repeats while (or until) a condition is met, when the number of repetitions is not known in advance, using a while or do ... until loop. Example: asking the user to enter a password until they get it right, where you do not know how many tries it will take.

Markers reward the known-versus-unknown number of repetitions distinction and a sensible example for each. Saying "for loops are faster" misses the point.

OCR 20225 marksA program should ask the user to guess a number between 1 and 10. If they guess 7 it prints "Correct", otherwise it prints "Wrong". Write an algorithm using selection, and then describe how you would change it so the user keeps guessing until they are correct.
Show worked answer →

Selection version (up to 3): read the guess, then use if/else.

guess = int(input("Guess a number 1 to 10: "))
if guess == 7 then
  print("Correct")
else
  print("Wrong")
endif

Marks: input (1), correct condition == 7 (1), correct output on each branch (1).

Changing it (up to 2): wrap the input and check in a condition-controlled loop that repeats until the guess is correct, for example a while guess != 7 loop, or a do ... until guess == 7 loop, so the user keeps guessing. Markers reward a correct loop that repeats the input and stops on the correct guess.

Related dot points

Sources & how we know this