OCR GCSE Computer Science June 2025 Paper 2, Question 2(a) and (b): a flowchart that loops

OCR J277/02 June 2025, Question 2(a) and (b): work out how many times a flowchart loop outputs OK for inputs of 3 and 10, then describe two kinds of iteration and name the other constructs. Worked through, with the loop to run.

Past paper questionOCR J277/02June 2025 Paper 28 marksRead the code

Question 2 of the OCR GCSE Computer Science Paper 2 sat on 20 May 2025 (J277/02) starts with a flowchart that uses iteration. Part (a) asks how many times it outputs "OK" for two inputs (2 marks). Part (b) asks you to describe two kinds of loop (4 marks) and to name the other two programming constructs (2 marks).

We do not copy the exam paper here. Open it beside this page: OCR June 2025 J277/02 question paper (PDF). When you have finished, check the mark scheme too.

The flowchart in short

It inputs x. Then it asks: is x less than 0? If that is true, it ends. If it is false, it outputs "OK", subtracts 2 from x, and goes back to the question.

The test comes before the output. That makes it a while loop.

Part (a): count the outputs

Input 3. 3 is not less than 0: OK, and x becomes 1. 1 is not less than 0: OK, and x becomes -1. -1 is less than 0: end. 2 times.

Input 10. The values of x at the test are 10, 8, 6, 4, 2, 0 and then -2. Each of the first six is not less than 0, so each gives an OK. 6 times.

Where the marks are lost in part (a)

  • 5 for the second answer. 0 is not less than 0, so there is one more OK when x is 0. That is the trap.
  • Counting the last test as a pass. When x is -2 the loop ends without an output.
  • Dividing by 2. 10 / 2 is 5, and the answer is 6. Trace it. Do not calculate it.

Part (b)(i): two examples of iteration

Two marks each: name it, and say how it repeats.

  • for loop: count-controlled. It repeats a set number of times.
  • while loop: condition-controlled. It repeats while a condition is true, and the condition is tested before each pass.
  • do ... until loop: condition-controlled. It repeats until a condition is true, and the condition is tested after each pass, so it always runs at least once.

If you choose while and do until, "condition-controlled" for both is only one point. Say how they differ. And do not mix them up: "a while loop repeats until a condition is true" is refused.

Part (b)(ii): the other two constructs

Sequence and selection. Examples such as "IF" are refused on their own. Name the construct.

Run it

The flowchart as a Python while loop. The robot drives 3 cm for every OK, so you can count them.

Enter 3 for two OKs and 10 for six. Try 0: one OK, because 0 is not less than 0. Try -1: none at all.
The program
from bugbot import *
connect()

x = int(input("Enter x: "))
count = 0
while not (x < 0):
    print("OK")
    count = count + 1
    forward(60, distance=3)
    x = x - 2
print("OK was output", count, "times")
Put this demo on your own site

Paste it into a school website, Moodle, Google Sites or a blog. More options on the embed page.

Questions

What are the answers to OCR J277 June 2025 Paper 2 Question 2(a)?

For an input of 3, OK is output 2 times. For an input of 10, OK is output 6 times.

What are the three types of loop?

A for loop is count-controlled and repeats a fixed number of times. A while loop is condition-controlled and tests its condition before each pass. A do until loop is condition-controlled and tests its condition after each pass.

What are the three programming constructs?

Sequence, selection and iteration.

More from this paper

Every OCR J277 question we have worked

Learn it step by step

  1. F5.2 Flowcharts Algorithms
  2. F2.6 Condition-controlled loops: while Decisions and loops
  3. F2.5 Count-controlled loops: for Decisions and loops
Open the lessons

This is our own explanation of a published exam question. It is not written or endorsed by OCR, and the question paper and mark scheme remain OCR's copyright. Read them on OCR's site with the links on this page.