This is a possible modification of the example program:

! MExample Program 8-1

! Manipulating an element in an array.

! Print out the contents of 1-D array Strength before modification

! Print out the contents of the array after modification

! do trace, fast (K , J, WorkingStrength) tracks the array contents

 

DIM Strength(1 to 20) ! sets the size of Strength ()

FOR J = 1 to 20 ! display the array

SET COLOR "red"

PRINT J; Strength (J),

NEXT J

PRINT

LET Strength(5) = 134.72 ! change a value

FOR J = 1 to 20

SET COLOR "blue"

PRINT J; Strength (J),

NEXT J

PRINT

FOR K = 1 to 3 ! change a range of values

LET Strength (K) = 34

NEXT K

FOR K = 9 to 18 ! change another range

LET Strength (K) = 666

NEXT K

FOR J = 1 to 20

SET COLOR "black"

PRINT J; Strength (J),

NEXT J

PRINT

LET WorkingStrength = Strength(5) / 2 ! extract and modify an element

SET COLOR "green"

PRINT "Working strength is"; WorkingStrength

SOUND 600,.2

END


The output produced is:

1 0 2 0 3 0 4 0 5 0

6 0 7 0 8 0 9 0 10 0

11 0 12 0 13 0 14 0 15 0

16 0 17 0 18 0 19 0 20 0

 

1 0 2 0 3 0 4 0 5 134.72

6 0 7 0 8 0 9 0 10 0

11 0 12 0 13 0 14 0 15 0

16 0 17 0 18 0 19 0 20 0

 

1 34 2 34 3 34 4 0 5 134.72

6 0 7 0 8 0 9 666 10 666

11 666 12 666 13 666 14 666 15 666

16 666 17 666 18 666 19 0 20 0

 

Working strength is 67.36