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.
298 exam-style questions on AQA GCSE Computer Science Programming concepts. Each one has a worked solution and a mark scheme showing where the marks go.