HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
Arrays and Files in Pseudocode
  1. 1One-dimensional arrays
  2. 2Two-dimensional arrays and nested loops
  3. 3Reading and writing files
  1. Computer Science
  2. /Arrays and Files in Pseudocode
  3. /One-dimensional arrays

Course 8.3·Lesson 1 of 3

One-dimensional arrays

One variable holds one value, but a class has thirty names. This lesson declares one-dimensional arrays in Cambridge pseudocode, writes values into them and reads them back with loops, and compares them with Python lists.

about 25 min1 simulation1 practice question
Lesson 1 of 3Show all lessonsHide
Arrays and Files in Pseudocode
  1. 1One-dimensional arrays
  2. 2Two-dimensional arrays and nested loops
  3. 3Reading and writing files

Try the code and the simulations beside the lesson.

Thirty names, one identifier

A teacher keeps thirty names. Thirty variables, Name1 to Name30, would be thirty lines to input and thirty lines to output. An array keeps them all under one identifier. Each value is an element, and a whole number, the index, says which one.

In the syllabus an array has a fixed length, and every element has the same data type. You met the Python form, the list, in the Python Foundations chapter "Lists: Many Values in One Variable". A Python list can grow and can mix types; a pseudocode array cannot.

Declaring an array

pseudocode
DECLARE StudentNames : ARRAY[1:30] OF STRING
DECLARE NoughtsAndCrosses : ARRAY[1:3, 1:3] OF CHAR

ARRAY[1:30] gives the lower bound 1 and the upper bound 30, so there are 30 elements. It is good practice to state the lower bound, because some systems start at 0 and some at 1. The syllabus usually uses 1. Python lists always start at 0.

![An array named Rainfall drawn as a row of seven boxes holding 4, 0, 12, 7, 0, 3 and 9. Above the boxes are the pseudocode indexes [1] to [7], below them the Python indexes 0 to 6. The third box, holding 12, is shaded, with the label Rainfall[3] = 12.](https://tuygolavdykfydmasiqc.supabase.co/storage/v1/object/public/discussion-images/57b80fd5-0d05-40b0-bb7c-fdadd190c00d/figures/ch08-programming-in-pseudocode-and-python/ics-g3-array.png)

The picture shows an array of seven rainfall readings. Rainfall[3] is 12. In Python the same element is rainfall[2], one less.

Using an element

An element is used just like a variable, with its index in square brackets: StudentNames[1] ← "Ali". The index can be a variable or an expression: StudentNames[n+1] ← StudentNames[n]. That is what makes arrays powerful: a loop counter can be the index.

Writing and reading with a loop

A FOR loop visits every element, one after the other. The syllabus example sets every name to the empty string:

pseudocode
FOR Index ← 1 TO 30
    StudentNames[Index] ← ""
NEXT Index

Here is a full program. The first loop inputs a week of rainfall into the array. The second loop reads the elements back to find the total and the wettest day.

pseudocode
DECLARE Rainfall : ARRAY[1:7] OF INTEGER
DECLARE Day : INTEGER
DECLARE Total : INTEGER
DECLARE Wettest : INTEGER
DECLARE WettestDay : INTEGER
FOR Day ← 1 TO 7
    OUTPUT "Rainfall in mm for day ", Day
    INPUT Rainfall[Day]
NEXT Day
Total ← 0
Wettest ← Rainfall[1]
WettestDay ← 1
FOR Day ← 1 TO 7
    Total ← Total + Rainfall[Day]
    IF Rainfall[Day] > Wettest
      THEN
        Wettest ← Rainfall[Day]
        WettestDay ← Day
    ENDIF
NEXT Day
OUTPUT "Total ", Total, " mm"
OUTPUT "Wettest day ", WettestDay

For the inputs 4, 0, 12, 7, 0, 3 and 9 millimetres, the output is Total 35 mm and then Wettest day 3. Look at the start of the second loop: Wettest begins as the first element, not as 0. Then a reading only replaces it when it is larger.

Searching an array

A linear search checks the elements one by one until it finds the value or runs out of elements. You will meet it as a standard method in the chapter on algorithms. Here it is on an array:

pseudocode
DECLARE Names : ARRAY[1:5] OF STRING
DECLARE Index : INTEGER
DECLARE Wanted : STRING
DECLARE Found : BOOLEAN
Names[1] ← "Ali"
Names[2] ← "Bea"
Names[3] ← "Cem"
Names[4] ← "Dana"
Names[5] ← "Eli"
INPUT Wanted
Found ← FALSE
Index ← 1
WHILE Found = FALSE AND Index <= 5 DO
    IF Names[Index] = Wanted
      THEN
        Found ← TRUE
      ELSE
        Index ← Index + 1
    ENDIF
ENDWHILE
IF Found
  THEN
    OUTPUT Wanted, " is at position ", Index
  ELSE
    OUTPUT Wanted, " is not in the list"
ENDIF

With the input Dana, the loop stops when Index is 4, and the output is Dana is at position 4. With Fay, Index goes past 5, and the output is Fay is not in the list. The test Index <= 5 stops the loop before it reads an element that does not exist.

Practise with new numbers

Try it in Python

The program is the rainfall example with a Python list. The readings are typed into the program, so it runs at once.

Read it first. Then run it. Do the total and the wettest day match the pseudocode?

1. Make the fifth reading 15. Predict the new wettest day, then run it.

2. Remove + 1 from the line wettest_day = day + 1. Why is the answer now one too small?

Common mistakes

  • An index outside the bounds. Rainfall[8] does not exist in ARRAY[1:7].
  • Mixing up 0 and 1. Pseudocode arrays usually start at 1; Python lists at 0.
  • Starting the largest value at 0. If every value is negative, 0 is wrong. Start with the first element.
  • Forgetting the index. Total ← Total + Rainfall has no index. Write Rainfall[Day].
  • Mixed data types. Every element of a pseudocode array has the same type.

Remember these

  • DECLARE Name : ARRAY[Lower:Upper] OF TYPE.
  • An element is Name[Index], and the index may be a variable or an expression.
  • Use a FOR loop from the lower bound to the upper bound to visit every element.
  • A pseudocode array has a fixed length and one data type.

Check yourself

Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.

  1. How many elements does ARRAY[0:9] OF REAL have?
  1. Write a statement that stores 25 in the last element of Rainfall.
  1. In the rainfall program, what is output for the readings 2, 6, 6, 1, 0, 5 and 3?
  1. Why does the search loop test Index <= 5?
  1. In Python, which index holds the element that pseudocode calls Rainfall[1]?

Enroll free in Arrays and Files in Pseudocode

Every lesson is open to read. Enrolling also lets you:

  • Mark lessons done and carry on where you stopped.
  • Count the course towards the certificate for its chapter.
No payment. You can leave at any time.

Problems (4)

A weather app stores one temperature in degrees Celsius for each day of a week…Easy · High School (9–10) · by StemPy Lab
Follow the program. What values does the array hold, and what are the two outputs?Medium · High School (9–10) · by StemPy Lab
A diver's depths below the surface are stored as negative heights in metres: -12, -5, -30, -5, -8…Hard · High School (9–10) · by StemPy Lab
Next: lesson 2Two-dimensional arrays and nested loops
← Arrays and Files in Pseudocode
← PreviousTwo-dimensional arrays and nested loops →

Discussion (0)

Log in to join the discussion.

Loading…

1 Python program
5 questions to check yourself

This lesson is free to read. Enroll free to keep your place in the course.

A program tries to move everyone in a queue back one place, to make room at the front…Medium · High School (9–10) · by StemPy Lab