BREAKING
Student's code works, nobody knows why, including student★Local teen writes pseudocode, accidentally invents a language★Binary joke told in class, exactly 10 students laugh★
  1. Home
  2. GCSE
  3. Computer Science
  4. OCR
  5. Sequence, selection and iteration

OCR GCSE Computer Science

Topic questions Programming fundamentals Sequence, selection & iteration

Sequence, selection & iteration

10 questions · 165 marks · about 3 hours

Sequence, selection and iteration questions

TopicSequence, selection & iteration

OCR J277 Sequence, selection and iteration 10 questions

Computational thinking, algorithms and programming June 2025, Question 2 12 marks

This flowchart uses iteration.

Figure for question 2
(a)

Complete the table by identifying how many times "OK" will be output for when each value is input.

Figure for question 2
[2]
Reveal mark scheme Mark scheme for question 2(a)
(b)

Iteration is a programming construct.

(b)(i)

Identify and describe two different examples of iteration that can be used in a high-level language.

[4]
Reveal mark scheme Mark scheme for question 2(b)(i)
(b)(ii)

Give the names of two other programming constructs that are used in a high-level language.

[2]
Reveal mark scheme Mark scheme for question 2(b)(ii)
(c)

A programmer implements the flowchart as a program in a high-level language using an Integrated Development Environment (IDE).

Identify and describe two tools that the programmer could use in the IDE to create a program from the flowchart.

[4]
Reveal mark scheme Mark scheme for question 2(c)

Computational thinking, algorithms and programming June 2025, Question 6 30 marks

OCR Rockfest is a yearly music festival. Visitors buy tickets to attend and watch the music acts.

A computer system is created to sell tickets and store information about visitors and the music acts.

(a)

Visitors are asked to choose a password. The password is entered twice and stored in the variables passA and passB

(a)(i)

Tick (✓) one box to identify the correct OCR Exam Reference Language statements for the design of this task.

Figure for question 6
[1]
Reveal mark scheme Mark scheme for question 6(a)(i)
(a)(ii)

Design an algorithm that:

• checks if the passwords stored in passA and passB are the same

• outputs "passwords match" if they are the same

• outputs "passwords do not match" if they are not the same.

[3]
Reveal mark scheme Mark scheme for question 6(a)(ii)
(b)

The database table TblMusic stores data about the music acts.

Some of the data in TblMusic is shown:

ActIDStageDaySetLength
1PlatinumSaturday0.5
2HillsSaturday1.5
3TriangleSunday1.0
4PlatinumSunday0.5

An SQL statement has been written to show ActID and Stage for all acts playing on Saturday. The SQL statement is incorrect.

SELECT ActID AND Stage FROM TblActs IF Day = Saturday

(b)(i)

Refine the SQL statement to correct the errors.

[4]
Reveal mark scheme Mark scheme for question 6(b)(i)
(b)(ii)

Identify one example of a record from TblMusic

[1]
Reveal mark scheme Mark scheme for question 6(b)(ii)
(b)(iii)

Give the most appropriate data type for each field shown.

Figure for question 6
[2]
Reveal mark scheme Mark scheme for question 6(b)(iii)
(c)

Tickets to the festival are £60 each. Visitors can buy multiple tickets. For example, a visitor buying 4 tickets would pay £240.

(c)(i)

Write a function, calculatePrice() that:

• takes the number of tickets to be purchased as a parameter

• calculates and returns the total price to pay.

You must use either:

• OCR Exam Reference Language, or

• a high-level programming language that you have studied.

[4]
Reveal mark scheme Mark scheme for question 6(c)(i)
(c)(ii)

Write an algorithm that:

• uses the function calculatePrice() to find the price for a visitor buying 3 tickets

• stores the result in the variable totalPrice

You must use either:

• OCR Exam Reference Language, or

• a high-level programming language that you have studied.

[2]
Reveal mark scheme Mark scheme for question 6(c)(ii)
(d)

The number of different music acts on each of the three stages is stored in the array actNumbers.

Each index of the array represents one stage.

Question 6, shown as an image
Figure for question 6
Question 6, shown as an image

This algorithm adds up the total number of acts on all three stages.

01 count = 0

02 for x = 0 to 2

03 count = count + actNumbers[x]

04 next x

05 print(count)

(d)(i)

Complete the trace table for the algorithm. You may not need to use all rows in the table.

Figure for question 6
[4]
Reveal mark scheme Mark scheme for question 6(d)(i)
(d)(ii)

The array actNumbers is changed to include data for two more stages. The new array is shown:

Index 0 1 2 3 4

Figure for question 6

The algorithm from part (i) needs refining to work for the new array. The algorithm is repeated here:

01 count = 0

02 for x = 0 to 2

03 count = count + actNumbers[x]

04 next x

05 print(count)

Identify the line number that will need to be changed for the new array and write the updated line of code.

[2]
Reveal mark scheme Mark scheme for question 6(d)(ii)
(d)(iii)

Refine line 05 in the algorithm to output "The total act count is " and then the content of the variable count

For example:

The total act count is 50

[1]
Reveal mark scheme Mark scheme for question 6(d)(iii)
(e)

There are 500 tickets available for the music festival. The number of tickets currently available is stored in the variable tickets

Complete the algorithm to:

• prompt the user to enter how many tickets they would like and take this value as input

• output "Tickets booked" and reduce the value stored in tickets if there are enough tickets available

• output "Not enough tickets" if there are not enough tickets available

• repeat the steps until there are no tickets left.

You must use either:

• OCR Exam Reference Language, or

• a high-level programming language that you have studied

tickets = 500

[6]
Reveal mark scheme Mark scheme for question 6(e)

Computational thinking, algorithms and programming June 2024, Question 8 10 marks

An algorithm stores the position of a character on a straight line as an integer. A user can move the character left or right.

The following algorithm:

• generates one random number between 1 and 512 (inclusive) to store as the position

• prompts the user to input a direction to move (left or right)

• takes a direction as input until a valid direction is input.

p = random(1, 512) print("The position is ", p) a = "" while a != "left" and a != "right" a = input("Enter direction, left or right") endwhile

(a)

Describe two ways to improve the maintainability of the algorithm.

[4]
Reveal mark scheme Mark scheme for question 8(a)
(b)

If the character moves left, 5 is subtracted from the position. If the character moves right, 5 is added to the position.

The position of the character can only be between 1 and 512 inclusive.

The function moveCharacter():

• takes the direction (left or right) and current position as parameters

• changes position based on direction

• sets position to 1 if the new position is less than 1

• sets position to 512 if the new position is greater than 512

• returns the new position.

Complete the function moveCharacter()

function moveCharacter(direction, position)

endfunction

[6]
Reveal mark scheme Mark scheme for question 8(b)

Computational thinking, algorithms and programming June 2023, Question 3 8 marks

An insertion sort is one type of sorting algorithm.

A student has written a pseudocode algorithm to perform an insertion sort on a 1D array names

names = ["Kareem", "Sarah", "Zac", "Sundip", "Anika"] for count = 1 to names.length – 1 pos = count while (pos > 0 and names[pos] < names[pos – 1]) temp = names[pos] names[pos] = names[pos – 1] names[pos – 1] = temp pos = pos – 1 endwhile next count

(a)

Describe the purpose of the variable temp in the insertion sort pseudocode algorithm.

[2]
Reveal mark scheme Mark scheme for question 3(a)
(b)

An insertion sort contains a nested loop; a loop within a loop. In this pseudocode algorithm the outer loop is a count-controlled loop and the inner loop is a condition-controlled loop.

Explain why the inner loop needs to be a condition-controlled loop.

[2]
Reveal mark scheme Mark scheme for question 3(b)
(c)

A bubble sort is another type of sorting algorithm.

(c)(i)

Describe one difference between an insertion sort and a bubble sort.

[2]
Reveal mark scheme Mark scheme for question 3(c)(i)
(c)(ii)

Describe two similarities between an insertion sort and a bubble sort.

[2]
Reveal mark scheme Mark scheme for question 3(c)(ii)

Computational thinking, algorithms and programming June 2023, Question 5 20 marks

Charlie is developing an adding game. The rules of the game are:

• the player is asked 3 addition questions

• each question asks the player to add together two random whole numbers between 1 and 10 inclusive

• if the player gets the correct answer, 1 is added to their score

• at the end of the game their score is displayed.

(a)

Charlie has been told that the game will need to be tested before giving it to the players.

(a)(i)

Explain why programs should be tested before use.

[2]
Reveal mark scheme Mark scheme for question 5(a)(i)
(a)(ii)

Complete the table by naming and describing one type of test that should be used on Charlie's program before releasing it.

Figure for question 5
[2]
Reveal mark scheme Mark scheme for question 5(a)(ii)
(a)(iii)

Complete the table by identifying and describing two features of an IDE that can be used when testing a program.

Figure for question 5
[4]
Reveal mark scheme Mark scheme for question 5(a)(iii)
(b)

Validating inputs can reduce errors when a program is being run.

Identify two methods of validation and explain how they can be used on this game.

Validation method 1........

Validation method 2........

[6]
Reveal mark scheme Mark scheme for question 5(b)
(c)

Write an algorithm to play this game. The rules are repeated from the start of the question here:

• the player is asked 3 addition questions

• each question asks the player to add together two random whole numbers between 1 and 10 inclusive

• if the player gets the correct answer, 1 is added to their score

• at the end of the game their score is displayed.

[6]
Reveal mark scheme Mark scheme for question 5(c)

Computational thinking, algorithms and programming June 2023, Question 6 30 marks

OCR Security Services is a company that installs intruder alarm systems in commercial buildings.

The systems use a computer that is connected to the door sensors and window sensors.

The following data is stored in the system:

Data storedVariable identifierExample data
The user’s nameUserNameAdmin123
A telephone number to call when the alarm is activatedEmergencyPhoneNumber+449999999999
Whether a door sensor is activatedDoorSensorActiveTrue
Whether a window sensor is activatedWindowSensorActiveTrue
A timer that counts, to the nearest second, how long a door sensor has been activatedDoorActiveTime100
A timer that counts, to the nearest second, how long a window sensor has been activatedWindowActiveTime100
Whether the system is armedSystemArmedTrue
Whether the system is in test modeTestModeActiveTrue
(a)

Below is a table showing some variables within the program.

Tick (✓) one box in each row to identify the most appropriate data type for each variable.

Figure for question 6
[4]
Reveal mark scheme Mark scheme for question 6(a)
(b)

The alarm has an algorithm that decides whether to sound the alarm by checking the data that is stored in the following three variables.

• SystemArmed

• DoorSensorActive

• WindowSensorActive

The alarm will only sound when the alarm has been activated and one or both of the door and window sensors are activated. When the system needs to sound the alarm it calls the pre-written procedure SoundAlarm()

Write a program that checks the data in the variables and calls SoundAlarm() when appropriate.

You must use either:

• OCR Exam Reference Language, or

• A high-level programming language that you have studied.

[4]
Reveal mark scheme Mark scheme for question 6(b)
(c)
Figure for question 6
(c)(i)

Give the line number where there is concatenation.

[1]
Reveal mark scheme Mark scheme for question 6(c)(i)
(c)(ii)

Give the identifier of a variable used in the program.

[1]
Reveal mark scheme Mark scheme for question 6(c)(ii)
(c)(iii)

Identify the data type of the data returned by the function CheckSensorCode()

[1]
Reveal mark scheme Mark scheme for question 6(c)(iii)
(c)(iv)

Give the line number that contains a function call.

[1]
Reveal mark scheme Mark scheme for question 6(c)(iv)
(c)(v)

Identify two programming constructs that have been used in the program.

[2]
Reveal mark scheme Mark scheme for question 6(c)(v)
(d)

The alarm system has a log that stores a record each time a sensor is triggered. This is called an event. The record format is given in the table:

FieldnameDescription
DateThe date the event happened
SensorIDThe sensor that was activated
SensorTypeThe type of sensor that was activated – Door, Motion or Window
LengthThe number of seconds the sensor was triggered (to the nearest second)

The log is stored in a database table called events. The current contents of events is shown:

DateSensorIDSensorTypeLength
05/02/2023WS2Window38
05/02/2023MS1Motion2
06/02/2023DS3Door1
06/02/2023MS2Motion3
06/02/2023MS1Motion2
07/02/2023WS1Window24
07/02/2023DS1Door1

Write an SQL statement to display the sensor IDs of the door sensors that have been triggered for more than 20 seconds.

[3]
Reveal mark scheme Mark scheme for question 6(d)
(e)

A program written in a high-level language is used to access the data from the database. This program has a procedure, SaveLogs(), that stores the data to an external text file.

The procedure SaveLogs():

• takes the string of data to be stored to the text file as a parameter

• takes the filename of the text file as a parameter

• stores the string of data to the text file.

Write the procedure SaveLogs()

You must use either:

• OCR Exam Reference Language, or

• A high-level programming language that you have studied.

[6]
Reveal mark scheme Mark scheme for question 6(e)
(f)

OCR Security Services need to identify the total number of seconds the sensors have been activated on a specific date.

The data from the database table events is imported into the program written in a high-level programming language.

The program stores the data in a two-dimensional (2D) string array with the identifier arrayEvents

The data to be stored is shown in the table.

DateSensorIDSensorTypeLength
05/02/2023WS2Window38
05/02/2023MS1Motion2
06/02/2023DS3Door1
06/02/2023MS2Motion3
06/02/2023MS1Motion2
07/02/2023WS1Window24
07/02/2023DS1Door1

In this table, the value of events[1, 1] contains "MS1".

(f)(i)

An array can only store data of one data type. Any non-string data must be converted to a string before storing in the array.

Identify the process that converts integer data to string data.

[1]
Reveal mark scheme Mark scheme for question 6(f)(i)
(f)(ii)

Write a program that:

• asks the user to input a date

• totals the number of seconds sensors have been activated on the date input

• outputs the calculated total in an appropriate message including the date, for example: Sensors were activated for 40 seconds on 05/02/2023

You must use either:

• OCR Exam Reference Language, or

• A high-level programming language that you have studied.

[6]
Reveal mark scheme Mark scheme for question 6(f)(ii)

Computational thinking, algorithms and programming June 2022, Question 1 7 marks

(a)

Tick (✓) one box in each row to identify whether the OCR Reference Language code given is an example of selection or iteration.

Figure for question 1
[4]
Reveal mark scheme Mark scheme for question 1(a)
(b)

Write pseudocode to increment the value held in the variable score by one.

[1]
Reveal mark scheme Mark scheme for question 1(b)
(c)

State the name of each of the following computational thinking techniques.

Breaking a complex problem down into smaller problems.

Hiding or removing irrelevant details from a problem to reduce the complexity.

[2]
Reveal mark scheme Mark scheme for question 1(c)

Computational thinking, algorithms and programming June 2022, Question 4 15 marks

Jack is writing a program to add up some numbers. His first attempt at the program is shown.

a = input("Enter a number") b = input("Enter a number") c = input("Enter a number") d = input("Enter a number") e = input("Enter a number") f = (a + b + c + d + e) print(f)

(a)

Give two ways that the maintainability of this program could be improved.

[2]
Reveal mark scheme Mark scheme for question 4(a)
(b)

Jack’s program uses the addition (+) arithmetic operator. This adds together two numbers.

(b)(i)

State the purpose of each of the arithmetic operators in the table.

Figure for question 4
[2]
Reveal mark scheme Mark scheme for question 4(b)(i)
(b)(ii)

Complete the description of programming languages and translators by writing the correct term from the box in each space.

continues crashes debugging error executable

high-level interpreter language low-level many

no one stops with without

Jack writes his program in a........ language. This needs to be

translated into assembly or machine code before it can be executed. This is done using

a translator.

One type of translator is an interpreter. This converts one line of code and then

executes it, before moving to the next line. It........ when an error is

found, and when corrected continues running from the same position. This translator is

helpful when debugging code.

A second type of translator is a compiler. This converts all of the code and produces

an error report. The code will not run until there are........ errors.

The........ file produced can be run........ the

compiler.

[5]
Reveal mark scheme Mark scheme for question 4(b)(ii)
(c)

Jack decides to improve his program. He wants to be able to input how many numbers to add together each time the algorithm runs, and also wants it to calculate and display the average of these numbers.

Write an algorithm to:

• ask the user to input the quantity of numbers they want to enter and read this value as input

• repeatedly take a number as input, until the quantity of numbers the user input has been entered

• calculate and output the total of these numbers

• calculate and output the average of these numbers.

[6]
Reveal mark scheme Mark scheme for question 4(c)

Computational thinking, algorithms and programming June 2022, Question 5 30 marks

Customers at a hotel can stay between 1 and 5 (inclusive) nights and can choose between a basic room or a premium room.

(a)

A typical booking record is shown in the table:

firstNameAmaya
surnameTaylor-Ling
nights3
roomPremium
stayCompleteFalse
(a)(i)

State the most appropriate data type for the following fields:

[2]
Reveal mark scheme Mark scheme for question 5(a)(i)
(a)(ii)

Give the name of one field that could be stored as a Boolean data type.

[1]
Reveal mark scheme Mark scheme for question 5(a)(ii)
(a)(iii)

Booking records are stored in a database table called TblBookings.

The following SQL statement is written to display all customer bookings that stay more than one night.

SELECT ALL FROM TblBookings IF Nights < 1

The SQL statement is incorrect.

Rewrite the SQL statement so that it is correct.

[4]
Reveal mark scheme Mark scheme for question 5(a)(iii)
(b)

When a new booking is recorded, the details are entered into a program to validate the values. The following criteria are checked:

• firstName and surname are not empty

• room is either “basic” or “premium”

• nights is between 1 and 5 (inclusive).

If any invalid data is found “NOT ALLOWED” is displayed. If all data is valid “ALLOWED” is displayed.

(b)(i)

Complete the following program to validate the inputs.

You must use either:

• OCR Exam Reference Language, or

• a high-level programming language that you have studied.

firstName = input("Enter a first name") surname = input("Enter a surname") room = input("Enter basic or premium") nights = input("Enter between 1 and 5 nights") stayComplete = False

[5]
Reveal mark scheme Mark scheme for question 5(b)(i)
(b)(ii)

Complete the following test plan to check whether the number of nights is validated correctly.

Test data (number of nights)Type of testExpected output
2ALLOWED
BoundaryALLOWED
Erroneous / InvalidNOT ALLOWED
[3]
Reveal mark scheme Mark scheme for question 5(b)(ii)
(c)

A Basic room costs £60 each night. A Premium room costs £80 each night.

(c)(i)

Create a function, newPrice(), that takes the number of nights and the type of room as parameters, calculates and returns the price to pay.

You do not have to validate these parameters.

You must use either:

• OCR Exam Reference Language, or

• a high-level programming language that you have studied.

[4]
Reveal mark scheme Mark scheme for question 5(c)(i)
(c)(ii)

Write program code, that uses newPrice(), to output the price of staying in a Premium room for 5 nights.

You must use either:

• OCR Exam Reference Language, or

• a high-level programming language that you have studied.

[3]
Reveal mark scheme Mark scheme for question 5(c)(ii)
(d)

The hotel has nine rooms that are numbered from room 0 to room 8.

The number of people currently staying in each room is stored in an array with the identifier room.

The index of room represents the room number.

Question 5, shown as an image
Index012345678
Data213210041

The following program counts how many people are currently staying in the hotel.

for count = 1 to 8 total = 0 total = total + room[count] next count print(total)

When tested, the program is found to contain two logic errors.

Describe how the program can be refined to remove these logic errors.

[2]
Reveal mark scheme Mark scheme for question 5(d)
(e)

The hotel car park charges £4 per hour. If the car is electric, this price is halved to £2 per hour.

Write an algorithm to:

• take as input the number of hours the user has parked and whether their car is electric or not

• calculate and output the total price

• repeat continually until the user enters 0 hours.

You must use either:

• OCR Exam Reference Language, or

• a high level programming language that you have studied.

[6]
Reveal mark scheme Mark scheme for question 5(e)

Report a problem with a question on this page
What is wrong?

Goes to whoever maintains the question split. No account needed and nothing is published on this page.

Memes

Certified Computer Science memes. Peer-reviewed by nobody.

Laugh now. Cry in the exam hall later. Then come back and do a past paper.

Write a proper algorithm
Write ‘sort it’ and leave
Me on the 6-mark pseudocode question
Debugging with print statements
Using a trace table
Knowing the difference between = and ==
Explaining recursion by explaining recursion
Code enlightenment, ranked

Mum 💖

can you fix the wifi since you do computers 🥰

that's not what computer science is

so that's a no then

📱 Screen time this week · Discord8h 2m

Turned it off and on again

Computer Science starter pack

Laptop with 47 tabs openPython error on line 1Counting binary on fingersThis website
Compiled with zero errors