Question bank › GCSE › GCSE Computer Science › Programming

Programming concepts: sequence, selection, iteration & Boolean/relational operators

10 questions48 marksabout 60 min

Answer on paper first, then reveal the mark scheme one mark at a time.

1Grade 4–54 marks

This algorithm calculates the price of a ticket.

age ← STRING_TO_INT(USERINPUT)
IF age < 5 THEN
   price ← 0
ELSE IF age < 16 THEN
   price ← 4
ELSE IF age ≥ 65 THEN
   price ← 5
ELSE
   price ← 9
ENDIF
OUTPUT price

State the output when the user enters:

(a) 3 [1]
(b) 16 [1]
(c) 70 [1]
(d) 15 [1]

2Grade 4–54 marks

Look at this algorithm.

scores ← [12, 5, 18, 7, 10]
total ← 0
count ← 0
FOR i ← 0 TO LEN(scores) - 1
   IF scores[i] ≥ 10 THEN
      total ← total + scores[i]
      count ← count + 1
   ENDIF
ENDFOR
OUTPUT total
OUTPUT count

(a) State the two values output by the algorithm. [2]

(b) Explain why a FOR loop has been used rather than a WHILE loop. [1]

(c) Write one line of AQA pseudocode, to be added at the end of the algorithm, that outputs the mean of the scores that were added to total. Your line must not use any fixed numbers, so that it would still give the correct mean if the values in scores were changed. You may assume at least one score is 10 or more. [1]

3Grade 1–34 marks

Lines 1 to 9 of a program are shown below. The line numbers are not part of the program.

1  CONSTANT MAX_TRIES ← 3
2  tries ← 0
3  WHILE tries < MAX_TRIES
4     guess ← STRING_TO_INT(USERINPUT)
5     IF guess = 7 THEN
6        OUTPUT "Correct"
7     ENDIF
8     tries ← tries + 1
9  ENDWHILE

(a) State the line number of the constant declaration. [1]

(b) State the line number of the line that begins a selection statement. [1]

(c) State the line number of the line that begins an iteration statement. [1]

(d) Give one reason why MAX_TRIES is a better identifier than m. [1]

Stuck on Programming concepts: sequence, selection, iteration & Boolean/relational operators?

Get it sorted in a free 30-minute session

We work through your weakest questions on this topic on Zoom. I reply the same day.

4Grade 4–54 marks

A program contains these three variables:

a ← 6
b ← 3
c ← 10

State whether each of the following expressions evaluates to TRUE or FALSE.

(a) a > b AND c ≤ 10 [1]

(b) NOT (a = 6) OR b ≠ 3 [1]

(c) (a MOD b = 0) OR NOT (c > a) [1]

(d) a + b > c AND NOT (b < a) [1]

5Grade 4–55 marks

This algorithm checks a password.

REPEAT
   password ← USERINPUT
UNTIL password = "open"
OUTPUT "Welcome"

(a) The user enters cat and then open. State how many times the statement password ← USERINPUT is executed. [1]

(b) Explain why a REPEAT … UNTIL loop is a suitable choice for this algorithm. [2]

(c) Rewrite the algorithm using a WHILE loop so that it behaves in exactly the same way. Use AQA pseudo-code. [2]

6Grade 6–74 marks

This algorithm uses nested iteration.

FOR i ← 1 TO 3
   FOR j ← i TO 3
      OUTPUT i * j
   ENDFOR
ENDFOR

(a) State how many times the OUTPUT statement is executed. [1]

(b) Give the values output, in order. [2]

(c) The inner loop is changed to FOR j ← 1 TO 3. State how many times the OUTPUT statement is now executed. [1]

7Grade 4–55 marks

A program is needed that repeatedly asks the user to enter a whole number. The program stops asking when the user enters 0. It then outputs how many of the numbers entered were negative. The 0 itself should not be counted.

Write the program using AQA pseudo-code or the programming language you have studied. [5]

8Grade 6–75 marks

Look at this algorithm.

n ← 20
steps ← 0
WHILE n > 1 AND steps < 5
   IF n MOD 2 = 0 THEN
      n ← n DIV 2
   ELSE
      n ← n * 3 + 1
   ENDIF
   steps ← steps + 1
ENDWHILE
OUTPUT n

(a) Complete the trace table for the algorithm. The first two rows have been done for you. [2]

nsteps
200
101
  
  
  
  

(b) State the value output by the algorithm. [1]

(c) State which part of the loop condition becomes FALSE and causes the loop to end. [1]

(d) The AND in the loop condition is changed to OR. State the value that is now output. [1]

9Grade 6–77 marks

A program awards a grade from a mark out of 100.

IF mark ≥ 40 THEN
   grade ← "Pass"
ENDIF
IF mark ≥ 70 THEN
   grade ← "Merit"
ENDIF
IF mark ≥ 85 THEN
   grade ← "Distinction"
ENDIF
IF mark < 40 THEN
   grade ← "Fail"
ENDIF
OUTPUT grade

(a) State the output when mark is 72. [1]

(b) State how many comparisons the program makes for any value of mark. [1]

(c) A programmer swaps the order of the first three IF statements so that the mark ≥ 85 test comes first and the mark ≥ 40 test comes third. State the output when mark is 90 and explain why. [2]

(d) Rewrite the program using a single IF … ELSE IF … ELSE structure so that it gives the correct grade for every mark and never makes more than three comparisons. Use AQA pseudo-code. [3]

10Grade 8–96 marks

This algorithm searches an array for the first value that is both even and greater than limit.

items ← [3, 8, 11, 14, 6, 20]
limit ← 10
i ← 0
found ← FALSE
WHILE i < LEN(items) AND NOT found
   IF items[i] MOD 2 = 0 AND items[i] > limit THEN
      found ← TRUE
   ELSE
      i ← i + 1
   ENDIF
ENDWHILE
IF found THEN
   OUTPUT items[i]
ELSE
   OUTPUT "None"
ENDIF

(a) State the value output. [1]

(b) State how many times the body of the WHILE loop is executed. [1]

(c) limit is changed to 25. State the output and the number of times the loop body is executed. [1]

(d) Explain what would happen if AND NOT found were removed from the loop condition. [2]

(e) Rewrite the loop condition without using NOT. [1]

Stuck on this topic?

Book a free 30-minute session on WhatsApp and we'll find exactly which step is costing you the marks. Or build a timed paper on it.

Free 30-minute session