Board Thread:Questions and Answers/@comment-24454571-20140517053531/@comment-5334617-20140520212213

"I don't understand the destinction there, of how Array of 10 can't = 42."

Do you understand why the statement "ARRAY(99)=2" wouldn't work? It's because 99 is too big. If 10 is the number in the DIM statement, then 10 is too big - 9 is as large as you can go for the index.

Let's try building up the program a step at a time, and understand each step. Start with the program

This program will do nothing.

Okay, I went a bit overboard when I said SmileBasic doesn't have any declarations at all. DIM is a declaration. So, this program declares four variables, ARRAY(0,0), ARRAY(0,1), ARRAY(1,0), and ARRAY(1,1) - provided the variable ARRAY has not previously been DIM-declared. If you RUN this program once, all will go as planned, if you RUN it a second time, you will get an error. So, one of the very first lines in many programs is

You can run this program again and again without error now. The values ARRAY(0,0) etc. will all be initialized to 0. If you had a line like, then the variables STRING$(0) etc. will all be initialized to the empty string "".

Now consider:

There is no array in the DATA/READ part here. There is just a list of variables after the READ keyword. The values get assigned to those values in order. At the end of this program, the variable X00 will be 3, the variable X01 will be 4, etc. (and all the ARRAY(#,#) values will still be at 0, because they have not been changed since the DIM). The variables could, of course, have been named ALICE, BOB, CHARLIE, and DAVE.

As far as ARRAY goes, the two pieces of code above will have the same effect. In the second piece of code, it is the order of the variables after the READ that indicates how the DATA, which is essentially one dimensional (just one value after another), fits into the "shape" of the array. You could write, and the same values would be in the array in different places. You could use  - and not every entry in ARRAY will get assigned a value. The list of variable names after READ, and what order they are in, is the key.