Lists: keeping many things together — Computing, 11–13 years
A list lets a program keep a group of related values in one organised place, so it can examine, change or repeat work on them.
What a list is
Imagine a row of labelled boxes: one for each score, name or colour. A list gives a program that row, with a position for every item. The program can ask for one item, replace it, or visit all the items in order.
Why lists were needed
A single variable works for one value, but a game may have 30 scores or a music app may have 500 songs. Giving every value a different name would be slow and hard to change. Lists solve this by letting one instruction work with a whole collection.
Adding scores
Suppose scores is [4, 7, 5]. First start total at 0. Read 4 and make total 4; read 7 and make it 11; read 5 and make it 16. The list has been visited item by item, so the final total is 16.
The first position
A common surprise is that some languages number positions from 0, not 1. In [red, blue, green], red is position 0 and blue is position 1. This feels wrong because people usually count from one, but computers use zero as the first step in an offset.
Lists outside school
Shopping apps use lists for products in a basket, and photo apps use them for pictures in an album. A weather service may keep today’s hourly temperatures in a list. The same idea helps software sort, search and display many related things.
Keep exploring
Other languages
Loading MyLeoNes™…