A-level Computer Science revision · Programming

Sequence, selection and iteration

The idea

Programs use three constructs. Sequence runs instructions in order. Selection (if, else if, switch/case) chooses a path. Iteration repeats: count-controlled (for loops) when the number of repeats is known; condition-controlled (while, do until) when it is not.

  1. Choose the construct for the task.
  2. For loops: known repeats. While: repeat until a condition changes.
  3. Trace values to check the logic.

Watch out A while loop checks its condition before running and may run zero times; a do-until loop runs at least once.

See it worked

Worked example

How many times does for i = 1 to 5 run?

  1. i takes 1, 2, 3, 4, 5.
  2. Five times.

Answer 5

Your turn

Question 12 marks

How many times is 'hello' printed by: for i = 0 to 8 step 2 / print('hello') / next i?

Question 21 mark

Which loop is best when you do not know how many times it will run?

Choose one
Question 31 mark

What is the value of total after: total = 0; for i = 1 to 4: total = total + i?

Choose one

A-level Computer Science Pro, OCR H446

A-level Computer Science Pro

£119 once

Price rises to £199 on 1 January. Save £80 by joining before then.

At least 12 months of access

By paying you agree to our Terms and get access straight away, which ends your 14-day cancellation right.

No VAT is charged.

Independent practice for OCR A-level Computer Science (H446), not endorsed by OCR.

Privacy · Terms