A game developer is writing a program to locate the position of a power-up (represented by the value 9) on a 3x3 coordinate grid.
Figure 1
power_up_row = -1
power_up_col = -1
for r in range(0, 3):
for c in range(0, 3):
if get_cell_value(r, c) == 9:
power_up_row = r
power_up_col = c
Figure 2
| Column 0 | Column 1 | Column 2 | |
|---|---|---|---|
| Row 0 | 1 | 5 | 2 |
| Row 1 | 4 | 0 | 9 |
| Row 2 | 3 | 7 | 6 |
Explain the purpose of the first iteration structure (the loop with control variable r) in Figure 1.
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.