Process a one-dimensional array with a loop
Use a variable index to read, write, initialise or calculate values across an array.
Section 8 · Programming
Exam scope and assessment notes
This sequence follows Cambridge IGCSE Computer Science 0478, 2026–2028 syllabus Version 6. It covers section 8.2 (Arrays) only. Pseudocode examples use the published Cambridge format; the separate 2029–2031 syllabus is not mapped here. Practice is original, self-checked and does not award an official Cambridge grade. Full timed papers, a browser-based programming workspace and human subject-teacher review remain outstanding.
Before you begin
- Be comfortable following an ordered algorithm and tracing variable values. Each lesson introduces the Cambridge pseudocode form it uses.
Work on paper. Try each question before revealing help, and explain why your method works.
Quick readiness check
What does Scores[Index] select?
What you will learn
- Assign array elements with iteration
- Read values through a variable index
- Use an array in a total or search
A loop visits one element at a time
Use a loop whose range matches the array's declared bounds. An index variable selects the current element: Scores[Index].
The same pattern can initialise elements, read input into them, or output them. The first index may be 0 or 1, so align the loop with the declaration.
Process each element consistently
A total can be calculated by setting Total to zero before the loop and adding each array element inside it.
For a search, compare the selected element with the target and record or output the relevant result. Avoid reading beyond the array's final index.
Pause and explain
Where should Total ← 0 appear when summing an array?
Worked example
Total the five values in Scores declared with indexes 1 to 5.
Show the worked solution
- Initialise Total ← 0.
- Loop Index from 1 through 5.
- Add Scores[Index] to Total on each pass.
Answer Total ← 0; FOR Index ← 1 TO 5; Total ← Total + Scores[Index]; NEXT Index.
Try a topic test
Choose Easy, Normal or Difficult. Save your answers and open worked review after finishing.
Test this topic →From guided practice to a new situation
Write your answer and reasoning first. Use a hint only if you are stuck. The model solution is for self-checking; your written work is not automatically marked.
A Values array has indexes 1 to 3 and stores 5, 2 and 8. Trace a loop that totals it.
Give me a hint
Add each selected value exactly once.
Compare my reasoning
- Start Total at 0.
- Add 5, then 2, then 8.
- The final total is 15.
Total = 15.
Look for these in your work
- Index range followed
- Values added
- Total correct
Write a FOR loop to read four integers into Data declared as ARRAY[1:4] OF INTEGER.
Give me a hint
INPUT can target one array element.
Compare my reasoning
- Loop Index from 1 to 4.
- Read into Data[Index].
- Close the loop after the input.
FOR Index ← 1 TO 4; INPUT Data[Index]; NEXT Index.
Look for these in your work
- Bounds align
- Variable index used
An array has 6 values at indexes 1–6. A search loop tests indexes 1–5 only. What can be missed and how should it be fixed?
Give me a hint
Compare the loop range with the declared range.
Compare my reasoning
- The sixth element is never examined.
- A matching target at index 6 is missed.
- Extend the loop through index 6.
The last element can be missed; search indexes 1 TO 6.
Look for these in your work
- Missing element identified
- Range corrected
Common mistakes
- Using a fixed index in every loop pass
- Starting or ending the loop outside the declared bounds
- Initialising the running total inside the loop
What can you explain now?
What lets one loop statement access a different array element each pass?
Compare with the explanation
A variable used as the index
The index changes as iteration proceeds.
After trying it yourself, choose your next review. This is your self-assessment.
Your review choice appears on Today. Sign in to sync it across devices.
Make it stick
How does a variable index make array processing reusable?
If you needed the solution, close it and solve the problem again from a blank page. A correct answer is stronger when you can explain the reason for each step.