Ages 8+ · Coding · Variables and data
Lists of things
Box number • box 0 • box 1 • box 2 • box 3 • box 4 Treasure • star • moon • sun • cloud • bolt Five treasure boxes, counted from zero. The big idea A list is a row of numbered boxes, and the first is number zero.
How it works A list is a row of numbered boxes. Things kept in order make a list.
Each box has a place number called an index, and the first box is number zero.
So the third box is number two, and five boxes run from zero up to four.
A list can grow: a new box joins at the end, and the old boxes keep their numbers.
1st box: index 0 2nd box: index 1 3rd box: index 2 4th box: index 3 5th box: index 4 Counting from zero. Example 1: Which box? The list is star, moon, sun, cloud, bolt. Mina wants the sun, which is the third treasure. Counting from zero, the sun is box number two. Example 2: The wrong number Mina asks for box number three, and out pops the cloud, the fourth treasure. She wanted the sun, so she should have asked for index two. Example 3: The last index There are five boxes: 0, 1, 2, 3 and 4. The last index is four, one less than the five boxes. Example 4: A list grows Tavi adds a new treasure on the end, at index five. The old boxes keep their numbers. Now six boxes run from zero up to five. Example 5: A swap Mina swaps the moon for a heart. The moon was in box one, so box one now holds the heart. The box keeps its number, and only what is inside it changes. Words to know list A row of numbered boxes. index A box's place number, counted from zero. box One place in the list that holds one thing. Watch out Counting starts at zero, so the third box is number two, not three. Five boxes run from zero to four, so the last index is four, not five. A box keeps its number when you swap what is inside it. One box with one name is a variable, not a list. Try it Which box holds the first thing in a list? A list has five things. What is the index of the last one? In the list star, moon, sun, cloud, bolt, what is in box 3? What is the index of the moon? A new treasure joins a list of five at the end. Which index does it get? Answers: 1. Box 0 · 2. 4 · 3. The cloud · 4. 1 · 5. 5
Try at home Line up five small things in a row, like a coin, a button, a spoon, a sock and a pen. Stick a paper number on each place, starting at zero. Ask a grown-up to say a number, and you hand them the thing at that place. Then swap two things and try again.
For grown-ups Play the Mission: line up five small things in a row, like a coin, a button, a spoon, a sock and a pen, with a paper number on each place starting at zero. Say a number and your child hands you the thing at that place. Then swap two things and try again.