Jump to content
IGNORED

Can someone explain setting up Arrays?


eddhell

Recommended Posts

I've read nanochess' book over and over, and I am just not understanding how to fill an array with specified data from a DATA statement.  I know you can use a For...next loop as a counter to "fill" the array, but I don't understand how to point the array to the specific DATA statements I want to use.

 

ok, so basically, I'm trying to fill an array with 10 preset numbers.  Here's the only way I could get it to work so far:

 

   DIM sqx(10)
  
read_array:
    RESTORE sqx
    FOR x = 0 to 9
      READ sqx(x)
    NEXT x

 

sqx:
    DATA 24,24,96,144,144,80,24,32,24,32

 

.....and it SEEMS to work fine.  BUT -When I try to add another array, how do I point it to another section of DATA?  Here's what I tried and it didn't work:

   

    DIM sqx(10)
    DIM sqy(10)


read_array:
    RESTORE sqx
    RESTORE sqy

    FOR x = 0 to 9
      READ sqx(x)

      READ sqy(x)
    NEXT x

 

sqx:
    DATA 24,24,96,144,144,80,24,32,24,32

 

sqy:

    DATA 64,16,32,24,80,72,56,64,24,16

 

 

there's something i'm just not getting with this...does the label before the DATA have to match the array name?  or is it all DATA statements read in sequential order?

 

 

Link to comment
Share on other sites

I thought restore only pointed to one set of data statements, although it is not a command I typically use.  

 

You could do something like this instead to store the contents of the two tables into two separate arrays:

  DIM sqx(10)
    DIM sqy(10)


read_array:
 

    FOR x = 0 to 9
      sqx(x) = table_x(x)

      sqy(x) = table_y(x)
    NEXT x

 

table_x:
    DATA 24,24,96,144,144,80,24,32,24,32

 

table_y:

    DATA 64,16,32,24,80,72,56,64,24,16

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...