User Tools

Site Tools


en:arrays

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
en:arrays [2016/05/28 03:24]
junior-root
en:arrays [2020/04/21 18:29] (current)
admin
Line 1: Line 1:
 ===== Arrays ===== ===== Arrays =====
 Arrays are allocated using the [[DIM|DIM]] command or re-sized using [[REDIM|REDIM]].  They may hold numeric or string data.  Access to specific elements in an array is accomplished by using square brackets along with the integer offset of the element, starting from zero.  Arrays may also be dimensioned and accessed using two dimensions.\\ Arrays are allocated using the [[DIM|DIM]] command or re-sized using [[REDIM|REDIM]].  They may hold numeric or string data.  Access to specific elements in an array is accomplished by using square brackets along with the integer offset of the element, starting from zero.  Arrays may also be dimensioned and accessed using two dimensions.\\
-Array sizes may also be extracted using [?] [?,] and [,?] on the end of the array variable. +[[arraylength|Array lengths]] may also be extracted using [?] [?,] and [,?] on the end of the array variable. 
-==== Example ====+ 
 +By default arrays may be indexed using an integer in the range of 0 to array_length-1.  You may optionally change the numeric array index to a range of 1 to array_length by using the [[arraybase|ArrayBase]] statement. 
 + 
 +==== Assigning values to an array ==== 
 + 
 +Values may be assigned to an array in one of five ways: 
 + 
 +1. By using the [[dim|Dim]] statement to reserve space for the array in the computer's memory and then assigning each individual element.
 <code> <code>
-print myarray[4]+dim a(10) 
 +for t = 0 to a[?]-1 
 +    a[t] = t 
 +next t
 </code> </code>
-will display on the screen the fifth element in 'myarray' 
  
 +2. By using a [[lists|list]] to create and assign an array.
 +<code>
 +a = {{0,1,2},{3,4,5},{6,7,8}}
 +</code>
 +or
 +<code>
 +b[] = {1,2,3,4}
 +</code>
 +
 +3. By using the [[dim|Dim]] statement to copy an existing array into another array.
 +<code>
 +a = {1,2,3,4}
 +dim b = a[]
 +</code>
 +
 +4. By using the [[explode|Explode]] or [[explodex|Explodex]] functions to split a string into an array.
 +<code>
 +a = explode("how now brown cow"," ")
 +</code>
 +
 +5. Using the [[fill|fill]] assignment operator (with or without [[dim|dim]])
 +<code>
 +dim c fill "stuff"
 +dim e[] fill 0
 +b fill ""
 +a[] fill -1
 +</code>
 +
 +==== Passing Arrays of Data to Builtin Functions and Statements ====
 +
 +When passing an array of data, like to the [[sound|sound]] statement, you may include an empty set of brackets [] after the variable name.  This was added to reduce the confusion between a regular variable and a variable containing an array of values.
 +
 +==== History ====
 +|1.99.99.55|added dim logic to copy one array to another|
 +|1.99.99.57|added the fill assignment operator|
 +|1.99.99.72|added the array passing note|
 +|2.0.0.0|Added ability to change array base|
en/arrays.1464427450.txt.gz · Last modified: 2020/02/28 10:46 (external edit)