Difference between revisions of "Recital Arrays"
From Recital Documentation Wiki
Barrymavin (Talk | contribs) |
Yvonnemilne (Talk | contribs) (→How to Create a Static Array in Recital) |
||
Line 2: | Line 2: | ||
===An Overview of Arrays in Recital=== | ===An Overview of Arrays in Recital=== | ||
===How to Create a Static Array in Recital=== | ===How to Create a Static Array in Recital=== | ||
+ | ====Static Arrays==== | ||
+ | |||
+ | A static array is an ordered list of elements (variables) that is of a fixed size (number of elements). You declare a static array by specifying the number of elements when you declare a variable. | ||
+ | |||
+ | <code lang="recital"> | ||
+ | private tab[ 20 ] // declare a static array of 20 elements all initialized to False | ||
+ | |||
+ | // iterate through the array (note the use of the alen( ) function to find the length of the array | ||
+ | for i=1 to alen( tab ) | ||
+ | // change each array element to hold a numeric value | ||
+ | tab[ i ] = i | ||
+ | endfor | ||
+ | </code> | ||
+ | |||
+ | You can initialize a static array with one statement. | ||
+ | |||
+ | <code lang="recital"> | ||
+ | // declare the array and init all elements to false | ||
+ | declare tab[10, 10] | ||
+ | |||
+ | // init all elements to zero | ||
+ | tab = 0 | ||
+ | </code> | ||
+ | |||
+ | You can create and initialize static arrays using '''static array initializers'''. | ||
+ | |||
+ | <code lang="recital"> | ||
+ | // simple one dimensional array with 2 elements | ||
+ | private tab = { "Hello", "world" } | ||
+ | |||
+ | // two-dimensional array of two rows with three columns in each row | ||
+ | private tab2 = { { "Hello", 10, date() ], { "world", 20, date()+1 } } | ||
+ | |||
+ | // create an array on the fly | ||
+ | mytab = { 10, 20, 30, 40, 50, 60 } | ||
+ | </code> | ||
+ | |||
+ | You can view the contents of a static array using the '''echo''' or '''?''' commands. | ||
+ | |||
+ | <code lang="recital"> | ||
+ | ? tab | ||
+ | </code> | ||
+ | |||
===How to Create an Associative Array in Recital=== | ===How to Create an Associative Array in Recital=== | ||
===Accessing Elements in a Static Array=== | ===Accessing Elements in a Static Array=== |
Revision as of 12:35, 27 January 2010
Contents
- 1 Recital Arrays
- 1.1 An Overview of Arrays in Recital
- 1.2 How to Create a Static Array in Recital
- 1.3 How to Create an Associative Array in Recital
- 1.4 Accessing Elements in a Static Array
- 1.5 Accessing Elements in an Associative Array
- 1.6 Changing, Adding and Removing Elements From Arrays
- 1.7 Looping Through Arrays
- 1.8 Replacing Sections of an Array
- 1.9 Sorting an Array
- 1.10 Passing Arrays as Function Arguments
- 1.11 Miscellaneous Array Functions
- 1.12 Summary
Recital Arrays
An Overview of Arrays in Recital
How to Create a Static Array in Recital
Static Arrays
A static array is an ordered list of elements (variables) that is of a fixed size (number of elements). You declare a static array by specifying the number of elements when you declare a variable.
private tab[ 20 ] // declare a static array of 20 elements all initialized to False // iterate through the array (note the use of the alen( ) function to find the length of the array for i=1 to alen( tab ) // change each array element to hold a numeric value tab[ i ] = i endfor
You can initialize a static array with one statement.
// declare the array and init all elements to false declare tab[10, 10] // init all elements to zero tab = 0
You can create and initialize static arrays using static array initializers.
// simple one dimensional array with 2 elements private tab = { "Hello", "world" } // two-dimensional array of two rows with three columns in each row private tab2 = { { "Hello", 10, date() ], { "world", 20, date()+1 } } // create an array on the fly mytab = { 10, 20, 30, 40, 50, 60 }
You can view the contents of a static array using the echo or ? commands.
? tab