A brief note on Arrays and Files . Read it before a test. Try each question at the end before you open its answer.
Arrays 1D: DECLARE Names : ARRAY[1:30] OF STRING. Fixed length, one data type. 2D: DECLARE Board : ARRAY[1:3, 1:3] OF CHAR. The row first, then the column. An element: Names[3], Board[2, 1]. The index may be a variable: Names[i]. Bounds: state the lower bound. Pseudocode usually starts at 1; Python lists at 0. Size of a 2D array: rows times columns. Loops over arrays Fill or read every element: FOR i ← 1 TO 30 ... NEXT i. 2D: nested loops, the outer for the rows, the inner for the columns. Largest or smallest: start with the first element, not with 0. Row totals: set the row total to 0 inside the outer loop, before the inner loop. Files Why: data in a file is kept after the program stops. OPENFILE "Name.txt" FOR READ or FOR WRITE. WRITE makes a new file; old data is lost. READFILE "Name.txt", Variable reads the next line. WRITEFILE "Name.txt", Value writes a line. CLOSEFILE "Name.txt" when you have finished. One mode at a time. Practice with new numbers
A program to try The program saves a 2D list to a file, one row a line, and reads it back.
Read it first. Then run it. Is the table read back the same as the one saved?
1. Add a fourth row to the table. What else must change in the program?
Mistakes to avoid An index outside the bounds, such as Names[31] in ARRAY[1:30]. The row and the column swapped in a 2D array. WRITE mode on a file you meant to keep. Reading in a different order from the order written. Forgetting CLOSEFILE. Check yourself How many elements does ARRAY[1:6, 1:5] have? Stuck? Show a hint Show the answerWrite the statement that reads the next line of Words.txt into NextWord. Stuck? Show a hint Show the answerWhy start the largest value at the first element of an array? Stuck? Show a hint Show the answerIn Python, how do you write the pseudocode element Board[1, 3] of a list of lists board? Stuck? Show a hint Show the answerA file is opened FOR READ. Can the program write to it before closing it? Stuck? Show a hint Show the answerSources Cambridge International, IGCSE Computer Science 0478 syllabus for 2026 to 2028, units 8.2 and 8.3 and section 4 (pseudocode).