A Row of Boxes: Arrays
One value, one box. That was a variable. But what if you need to hold a hundred things, like a class roll? You can't name a hundred boxes. So you line them up in one container. That's an array.
Drop values in, one by one. The row fills up.
Every slot gets a position number.
Computers count positions from 0, so the first slot is number 0.
Pick a number and that slot lights up. "What's sitting in slot 2?"
How many are there
The row can grow or shrink, and you can always count how many slots it holds.
Add some, remove some. The count follows along.
Walking one slot at a time
The loop from lesson 7 really shines here.
From the first slot to the last, you walk one step at a time and look at every one.
Hit play. It hops slot by slot, scanning the whole row.
A row has order
Swap two slots and they trade places. Squeeze one into the middle and everything behind shifts over.
Because it's a row, the order means something.
Tap two slots to swap them. Insert in the middle and the rest slide back.
Inside the computer these slots really do sit side by side, like lockers in a row.
A container that labels each slot by name is coming up next.