Multidimensional Anonymous Arrays (Language Help)

by Steve K, Saturday, February 25, 2012, 10:34 (1855 days ago)

Hi guys, I'm just starting out with BASIC256 and I'm hoping to teach it to a class of children soon. It's looking quite good so far but I've hit a small problem: is there any way to initialise a multidimensional array? Something like:

grid = { { 1, 2, 3, 1, 1 },
{ 2, 0, 2, 1, 0 },
{ 0, 1, 1, 2, 3 },
{ 3, 2, 1, 0, 0 },
{ 0, 1, 2, 0, 3 } }

I could possibly use one big one-dimensional array instead, or load the data from a file, but these are complications I was hoping to avoid at the moment.

Anyway, thanks for making this neat little language :)

Multidimensional Anonymous Arrays

by jwc3119, Monday, February 27, 2012, 09:23 (1853 days ago) @ Steve K

the dimension statement for a two dimensional array (for a 5x5 array called "grid" is just:

dim grid(5,5)

(remember that each array index for this case would go from 0 to 4 and not 1 to 5)

Hi guys, I'm just starting out with BASIC256 and I'm hoping to teach it to a class of children soon. It's looking quite good so far but I've hit a small problem: is there any way to initialise a multidimensional array? Something like:

grid = { { 1, 2, 3, 1, 1 },
{ 2, 0, 2, 1, 0 },
{ 0, 1, 1, 2, 3 },
{ 3, 2, 1, 0, 0 },
{ 0, 1, 2, 0, 3 } }

I could possibly use one big one-dimensional array instead, or load the data from a file, but these are complications I was hoping to avoid at the moment.

Anyway, thanks for making this neat little language :)

Multidimensional Anonymous Arrays

by Jim ⌂ @, Russell, KY, Monday, February 27, 2012, 16:41 (1853 days ago) @ Steve K

You can initialize a two dimensional array using the curly braces as if it were a single dimension array. The columns are filled across the rows as you can see here.

dim a(3,4)
a = {1,2,3,4,5,6,7,8,9,10,11,12}
for r = 0 to 2
for c = 0 to 3
print a[r,c]+" ";
next c
print
next r

Multidimensional Anonymous Arrays

by Steve K, Monday, February 27, 2012, 17:26 (1853 days ago) @ Jim

Now why didn't I think of that? Thanks!

Multidimensional Anonymous Arrays

by jwc3119, Tuesday, February 28, 2012, 08:20 (1852 days ago) @ Jim

that's a handy thing to know, thanks

RSS Feed of thread
powered by my little forum