Easy1 markMultiple Choice
Fundamentals of algorithmsGeneralcontrol structuresiterationpseudo-code

AQA GCSE · Question 02.1 · Fundamentals of algorithms

Figure 2 shows an algorithm that uses integer division which has been represented using pseudo-code. Line numbers are included but are not part of the algorithm.

Figure 2
1 again ← True
2 WHILE again = True
3 a ← USERINPUT
4 IF a > 0 THEN
5 counter ← 0
6 WHILE a > 0
7 a ← a DIV 3
8 counter ← counter + 1
9 ENDWHILE
10 ELSE
11 again ← False
12 ENDIF
13 OUTPUT a
14 ENDWHILE
Where is iteration first used in the algorithm in Figure 2?

Answer options:

A.

Line number 2

B.

Line number 4

C.

Line number 6

D.

Line number 11

How to approach this question

1. Understand the term "iteration". Iteration refers to the repetition of a block of code. Common iteration structures are `FOR` loops and `WHILE` loops. 2. Scan the code in Figure 2 from top to bottom. 3. Line 2 contains `WHILE again = True`. This is the beginning of a loop. 4. Line 6 also contains a `WHILE` loop, but since it appears after line 2, the loop on line 2 is the first instance of iteration in the algorithm.

Full Answer

A.Line number 2✓ Correct
In programming, there are three basic control structures: sequence, selection, and iteration. - **Sequence:** Instructions are executed one after another. - **Selection:** A choice is made between different paths of execution (e.g., `IF-THEN-ELSE`). - **Iteration:** A block of code is executed repeatedly (e.g., `WHILE` loops, `FOR` loops). The question asks for the first use of iteration. The `WHILE` loop on line 2 is the first iterative construct in the algorithm. The `IF` statement on line 4 is selection. The `WHILE` loop on line 6 is also iteration, but it occurs after the one on line 2.

Common mistakes

✗ Confusing selection (`IF` statements) with iteration (`WHILE` loops).\n✗ Identifying the second loop (line 6) instead of the first one (line 2).

Practice the full AQA GCSE Computer Science Paper 1 Python

31 questions · hints · full answers · grading

More questions from this exam