Think about it. A spreadsheet can hold hundreds of values. A game needs to keep track of points, positions, how to draw the image. A browser needs to keep track of the URL, how to layout the webpage, and so forth.
Any reasonable computations requires many boxes.
Now that we have so many boxes, we need a way to identify one box from another box. In the previous lesson, when we performed a read or write operation, we knew exactly which box we were reading from or writing to.
We're going to have one restriction. Even though we have many boxes, we can only read or write to one box at a time. However, now we need to say which box we wish to read from or write to.
We'll number the boxes starting at 0. Why 0? It turns out numbering from 0 is very common in computer programming. As weird as that is, you need to get used to it. So why not get used to it right now.
If we have 3 boxes, we number them box 0, box 1, and box 2.
If we have 10 boxes, the boxes are numbered from box 0 up to box 9.
If we have N boxes, the boxes are numbered from box 0 up to box N - 1. We'll often refer to N rather than a specific number. You see the use of variables such as N a lot in computer programming, so you might as well get used to it now.
We have two numbers for a box: the box ID and the value in the box. For example, box 3 may have the value -1. Box 10 may have the value 100. Box 12 might have the value 12.
When you hear a number and a box, you need to distinguish between the box ID and the box value. The box ID tells you the box we're referring to, and the box value is the value inside the box.
Now that we have more than one box, we need to modify the commands to indicate which box we're talking about.
In particular, we'll now say:
When you write to a box, only that value is changed. The other boxes are unchanged.
To do this exercise, draw three boxes, left to right. Above the first box, write the number 0 (that's box 0). For the middle box, write the number 1. For the right box, write the number 2. Inside each box, write the number 0. That's the initial value of each box.
Let's begin: