The two subroutines in Figure 1 and Figure 2 are designed to count how many times a population P P\,P can be halved before it falls to 1 or below.
SUBROUTINE countHalvings(P)
count ← 0
WHILE P > 1
P ← P / 2
count ← count + 1
ENDWHILE
OUTPUT count
ENDSUBROUTINE
SUBROUTINE countHalvings(P)
count ← 0
REPEAT
P ← P / 2
count ← count + 1
UNTIL P ≤ 1
OUTPUT count
ENDSUBROUTINE
Describe two differences in the way the loops in Figure 1 and Figure 2 operate.
Practise AQA GCSE Computer Science Programming concepts with exam-style questions for GCSE Computer Science. 100 questions, matched to the AQA GCSE Computer Science (8525) specification and written in Paper 1 and Paper 2 style. Every question includes a full worked solution and mark scheme, so you can see where marks are awarded rather than just whether you got the answer right.