Assign values to an array.

Post Reply
Ken
Posts: 29
Joined: Tue Jan 29, 2019 1:49 am
My devices: Ipad
Location: NSW, Australia

Assign values to an array.

Post by Ken »

Hi
If I have a dimensioned array, say Dim x(3), how can I assign a value to each part. Say 20, 30, 40
Thanks

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: Assign values to an array.

Post by rbytes »

If I have a dimensioned array, say Dim x(3), how can I assign a value to each part. Say 20, 30, 40
You can do it with individual value assignments:

X(1)=20
X(2)=30
X(3)=40

Or use a loop to assign the values:

FOR t=2 TO 4
X(t-1)=t*10
NEXT t

The loop is probably overkill for this small number of value assignments, but becomes more and more efficient as the number increases.

No need to DIM x unless you need it dimensioned larger than 10. And case doesn't matter in a variable, so X is the same as x.
The only thing that gets me down is gravity...

Ken
Posts: 29
Joined: Tue Jan 29, 2019 1:49 am
My devices: Ipad
Location: NSW, Australia

Re: Assign values to an array.

Post by Ken »

Hi
Thanks for that.
What if I have a mixed up set of values say to make a polygon. X is 23, 56, 67 y is 43, 59, 120 etc. I am guessing I would use data and read. Is that the best way?
Ken

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: Assign values to an array.

Post by rbytes »

Yes, that works very well. Use a loop to read the x and y values from DATA statements into two arrays named x and y

Then use the poly command to draw the shape. Notice that where X and Y appear in the poly command, arrays are expected. The parameters shown in square brackets are optional.

DRAW POLY X,Y [COUNT N START S]

Give it a try and if you need an example afterward I can post one.
The only thing that gets me down is gravity...

Post Reply