Scripting 5.6. Arrays

You can use arrays of numeric and string variables:

for i from 1 to 5
    square [i] = i * i
    text$ [i] = mid$ ("hello", i)
endfor

After this, the variables square [1], square [2], square [3], square [4], square [5], text$ [1], text$ [2], text$ [3], text$ [4], and text$ [5] contain the values 1, 4, 9, 16, 25, "h", "e", "l", "l", and "o", respectively.

You can use any number of variables in a script, but you can also use Matrix or Sound objects for arrays.

You can substitute variables with the usual single quotes, as in 'square[3]', without spaces. If the index is also a variable, however, you may need a dummy variable:

echo Some squares:
for i from 1 to 5
   hop = square [i]
   printline The square of 'i' is 'hop'
endfor

Links to this page


© ppgb, November 18, 2010