Level:
Correct: 0
Incorrect: 0
Marks: 0/0
Exam Practice
Course:
Topics:
AQA GCSE Computer Science (Paper 1) Smart practice A mixed round aimed at your weak spots
Unit 1
3.1 Fundamentals of algorithms
Unit 2
3.2 Programming
Data types
Data types
Arithmetic operations in a programming language
Arithmetic operations, DIV and MOD
Relational operations in a programming language
Relational operations
Boolean operations in a programming language
Boolean operations in conditions
Data structures
Arrays and records
Input/output
Input and output
String handling operations in a programming language
String handling
Random number generation in a programming language
Random number generation
Structured programming and subroutines (procedures and functions)
Subroutines and structured programming
Avg
score:
–
Topics
done:
0/15

Variables, constants, selection and iteration

Practise 35 exam-style questions on Variables, constants, selection and iteration for AQA GCSE Computer Science (Paper 1). Write your answer as you would in the exam and get it marked in seconds against the mark scheme, point by point, with the Study Helper on hand if you get stuck.

  • 35 questions
  • 1–10 marks each
  • Instant marking
  • No sign-up needed
20 questions, marked as you go

Sample questions with model answers

Here are 4 of the questions in this topic, each with a model answer, an explanation of why it earns the marks and the mark scheme an examiner would use.

Question 1

1 mark

How many times is Hello output when the algorithm below is executed?

FOR i ← 3 TO 9 STEP 2
  OUTPUT 'Hello'
ENDFOR

Choose your answer.

  • 3
  • 4
  • 6
  • 7

Model answer

4

Explanation

With STEP 2, i takes the values 3, 5, 7 and 9, and the loop stops because the next value, 11, would be past the upper limit of 9. That is four repetitions, because the limit 9 is included. 7 comes from ignoring the STEP, and 3 from wrongly leaving out the final value 9.

Mark scheme
  1. 1 mark

    4

    Mark is for AO2 (apply). If more than one option is given, 0 marks.

Question 2

2 marks

The algorithm below is used by a PE teacher to plan a training session.

01FOR lap ← 1 TO 4
02  OUTPUT lap
03  FOR cone ← 1 TO 6
04    OUTPUT 'Cone'
05  ENDFOR
06ENDFOR

State how many times line 2 is executed and how many times line 4 is executed.

Model answer

Line 2 is executed 4 times.
Line 4 is executed 24 times.

Explanation

Line 2 is inside the outer loop only, so it runs once for each of the 4 laps. Line 4 is inside both loops: the inner loop runs all 6 times for every lap, so line 4 runs 4 × 6 = 24 times. Adding 4 + 6 = 10 instead of multiplying is the usual mistake.

Mark scheme
  1. 1 mark

    Line 2: 4 (times)

    Both marks AO2 (apply).

  2. 1 mark

    Line 4: 24 (times)

    R. 6. R. 10.

Question 3

3 marks

Some programming languages, such as C#, have a DO ... WHILE iteration structure. DO ... WHILE is not part of AQA pseudo-code, but it has been added to the pseudo-code in the algorithm below.

secret ← 7
DO
  guess ← USERINPUT
WHILE guess ≠ secret
OUTPUT 'Correct'

Give one similarity and one difference between a DO ... WHILE loop and a REPEAT ... UNTIL loop, and rewrite the algorithm using REPEAT ... UNTIL so that it works in the same way.

Model answer

Similarity: both check their condition at the end, so the body always runs at least once.
Difference: DO ... WHILE keeps repeating while its condition is True, whereas REPEAT ... UNTIL keeps repeating until its condition becomes True, so the two conditions are opposites.

secret ← 7
REPEAT
  guess ← USERINPUT
UNTIL guess = secret
OUTPUT 'Correct'

Explanation

Both structures are post-condition loops: the user is always asked for at least one guess before any test is made. DO ... WHILE continues while guess ≠ secret is True, so the equivalent REPEAT ... UNTIL must stop when the opposite, guess = secret, becomes True. Keeping ≠ in the UNTIL condition is the common mistake: that loop would stop after the first wrong guess.

Mark scheme
  1. 1 mark

    Similarity: both test their condition at the end of the loop // both always execute the body at least once

    2 marks for AO1 (understanding) and 1 mark for AO2 (apply).

  2. 1 mark

    Difference: DO ... WHILE repeats while its condition is True (it stops when the condition becomes False), but REPEAT ... UNTIL repeats until its condition is True (it stops when the condition becomes True) // the conditions needed are opposites

    R. differences in syntax only, e.g. 'one starts with the word DO'.

  3. 1 mark

    secret ← 7, REPEAT, guess ← USERINPUT, UNTIL guess = secret, OUTPUT 'Correct' (one statement per line, in this order)

    The UNTIL condition must be guess = secret (A. NOT (guess ≠ secret)). R. UNTIL guess ≠ secret. I. Case. A. program code with the same logic.

Question 4

5 marks

The algorithm below uses nested iteration.

count ← 0
FOR row ← 1 TO 3
  FOR col ← row TO 3
    count ← count + 1
    OUTPUT row * col
  ENDFOR
ENDFOR
OUTPUT count

Complete the trace table shown in the figure for the algorithm. The first row has been completed for you.

Give your answer as the values in each column, in order.

Trace table with four columns: count, row, col and OUTPUT. Row 1: count = 0; row, col and OUTPUT blank. Rows 2 to 10 are empty, for the student to complete.

Model answer

count: 0, 1, 2, 3, 4, 5, 6
row: 1, 2, 3
col: 1, 2, 3, 2, 3, 3
OUTPUT: 1, 2, 3, 4, 6, 9, 6

Explanation

The inner loop starts at the current value of row, so it runs three times when row is 1, twice when row is 2 and once when row is 3 - six times altogether. Each time it runs, count goes up by 1 and the product row * col is output. The final value of count, 6, is output once after both loops finish; a common mistake is to start col at 1 every time, which gives nine passes.

Mark scheme
  1. 1 mark

    row column: 1, 2, 3

    All marks AO2 (apply). I. Repeated values on rows where a value has not changed. I. Different rows used, as long as the order within each column is clear. I. Whether or not the values given in the first row are repeated.

  2. 1 mark

    col column: 1, 2, 3, 2, 3, 3

  3. 1 mark

    count column: 0, 1, 2, 3, 4, 5, 6

  4. 1 mark

    OUTPUT values from inside the loops: 1, 2, 3, 4, 6, 9 in this order

  5. 1 mark

    Final OUTPUT: 6, output once after both loops have finished

    R. 9.

Ready to try the rest? Every answer you write is marked against the mark scheme, so you can see exactly where the marks are.

Study Helper Hints first, answers after you try

Stuck on this one? Ask for a hint and I’ll point you in the right direction, without giving the answer away. Once you’ve checked your answer, I’ll show you how the marks are awarded.