Arrays are variables with members which are only referenced numerically using an index value. Arrays support negative indexing, meaning that -1, -2, etc. references the last, 2nd last and further array elements. A variable cannot be an array and a structure at the same time, i.e referencing an array with a member name causes an error.
Base Variable Name | [ | Index | ] |
---|---|---|---|
- String value or expression | - Numeral or numeric expression | ||
as variable name | as index number |
Syntax for referencing arrays: Variable Name [ index ]
Following rules apply to the index:
Following approaches are available to create arrays:
dim...() function family | Functions such as dim(), redim(), dim protect() and redim protect() initialize arrays with a specified number of elements and initial values. |
array...() | Functions like array() and array protect() create arrays with initial values provided in sets. |
Direct referencing | (Spontaneous array creation) Assigning a simple variable with an index will automatically create an array with members 0...index where the members inbetween are not initialized and return void values. |
Individual member variables may be deleted using the delete() function. If a member in the beginning or middle of the arrary is deleted, then all other members move up accordingly.
echo("Initialize variable with dim function:");
dim( a[], 5, '.' );
see( a[] );
echo(new line, "Initialize variable with array function:");
array( a[], { Ha, He, Hi, Ho, Hu, Ahoi } );
see( a[] );
Initialize variable with dim function:
a[] [Void] (void,full access)
Array [ 0] . (softquoted string,full access)
Array [ 1] . (softquoted string,full access)
Array [ 2] . (softquoted string,full access)
Array [ 3] . (softquoted string,full access)
Array [ 4] . (softquoted string,full access)
Initialize variable with array function:
a[] [Void] (void,full access)
Array [ 0] Ha (softquoted string,full access)
Array [ 1] He (softquoted string,full access)
Array [ 2] Hi (softquoted string,full access)
Array [ 3] Ho (softquoted string,full access)
Array [ 4] Hu (softquoted string,full access)
Array [ 5] Ahoi (softquoted string,full access)
Nesting is supported: Every array element may be a simple variable, a further array of any size or a structure.
A (m x n) multi-dimensional array is a nested array with m members and each member containing n sub-members.
Since Beyond4P variable structure is a tree with values possible in both root, intermediate and end nodes, the base variables as well as
member variables of those containing sub-members are preserved.
Nested arrays:
Base Variable Name | [ | Index | , | Index | ] |
---|---|---|---|---|---|
- String value or expression | - Numeral or numeric expression | - Numeral or numeric expression | |||
as variable name | as index number | as index number |
echo("Initialize a 2-dimensional array:");
dim( a[], {2,3}, '0' );
see( a[] );
echo(new line, "Initialize two arrays (2nd one is nested) implicitly:");
b[2] = true;
b[1,2] = 123;
see( b[] );
Initialize a 2-dimensional array:
a[] [Void] (void,full access)
Array [ 0] 0 (softquoted string,full access)
Array [ 0] 0 (softquoted string,full access)
Array [ 1] 0 (softquoted string,full access)
Array [ 2] 0 (softquoted string,full access)
Array [ 1] 0 (softquoted string,full access)
Array [ 0] 0 (softquoted string,full access)
Array [ 1] 0 (softquoted string,full access)
Array [ 2] 0 (softquoted string,full access)
Initialize two arrays (2nd one is nested) implicitly:
b[] [Void] (void,full access)
Array [ 0] [Void] (void,full access)
Array [ 1] [Void] (void,full access)
Array [ 0] [Void] (void,full access)
Array [ 1] [Void] (void,full access)
Array [ 2] 123 "123" (numeral,full access)
Array [ 2] true (boolean,full access)