Shop OBEX P1 Docs P2 Docs Learn Events
How to definition two dimension array? — Parallax Forums

How to definition two dimension array?

kevinspacekevinspace Posts: 56
edited 2011-12-24 07:03 in Propeller 1
Hello everyone~
Are there anyone know that how to definition two dimension array?
Just like it :
var
long a[3][4]

pub main
a[0][0] := 1
a[0][1] := 2
a[0][2] := 3
a[0][3] := 4

a[1][0] := 5
a[1][1] := 6
a[1][2] := 7
a[1][3] := 8

a[2][0] := 9
a[2][1] := 10
a[2][2] := 11
a[2][3] := 12

Are there any example or any suggestion?
Thanks a lot.

Comments

  • JasonDorieJasonDorie Posts: 1,930
    edited 2011-12-24 02:54
    I don't think that's possible in SPIN, however you can create a 1D array and manage the addressing yourself, like this:
    var
      long a[3 * 4]
    
    pub main
      a[0*4 + 0] := 1
      a[0*4 + 1] := 2
      a[0*4 + 2] := 3
      a[0*4 + 3] := 4
    
      a[1*4 + 0] := 5
      a[1*4 + 1] := 6
      a[1*4 + 2] := 7
      a[1*4 + 3] := 8
    
  • localrogerlocalroger Posts: 3,452
    edited 2011-12-24 07:03
    Jason is right, Spin doesn't support 2D arrays. But the method he shows can be used to fake them.
Sign In or Register to comment.