Arrays: Difference between revisions

Content added Content deleted
No edit summary
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 178: Line 178:
[1,"one", 2, "two"]
[1,"one", 2, "two"]
</lang>
</lang>

=={{header|AArch64 Assembly}}==
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
Line 327: Line 328:
.include "../includeARM64.inc"
.include "../includeARM64.inc"
</lang>
</lang>

=={{header|ABAP}}==
=={{header|ABAP}}==
There are no real arrays in ABAP but a construct called internal tables.
There are no real arrays in ABAP but a construct called internal tables.
Line 389: Line 391:
//get and remove the last element of an array
//get and remove the last element of an array
trace(array2.pop());</lang>
trace(array2.pop());</lang>

=={{header|Ada}}==
=={{header|Ada}}==
<lang Ada>procedure Array_Test is
<lang Ada>procedure Array_Test is
Line 552: Line 555:
/ Get the nth element (index origin = 0)
/ Get the nth element (index origin = 0)
nth:arr[n]</lang>
nth:arr[n]</lang>

=={{header|Apex}}==
<lang apex>Integer[] array = new Integer[10]; // optionally, append a braced list of Integers like "{1, 2, 3}"
array[0] = 42;
System.debug(array[0]); // Prints 42</lang>
Dynamic arrays can be made using <code>List</code>s. <code>List</code>s and array can be used interchangeably in Apex, e.g. any method that accepts a <code>List<String></code> will also accept a <code>String[]</code>
<lang apex>List <Integer> aList = new List <Integer>(); // optionally add an initial size as an argument
aList.add(5);// appends to the end of the list
aList.add(1, 6);// assigns the element at index 1
System.debug(list[0]); // Prints 5, alternatively you can use list.get(0)</lang>


=={{header|APL}}==
=={{header|APL}}==
Line 563: Line 576:
All supported data types may be stored in a List.
All supported data types may be stored in a List.
[https://lh4.googleusercontent.com/-5y13nsUEj1U/UunGAhuqWEI/AAAAAAAAJ7U/i2IL5v6EQ5I/w631-h658-no/Capture.PNG Basic List blocks]
[https://lh4.googleusercontent.com/-5y13nsUEj1U/UunGAhuqWEI/AAAAAAAAJ7U/i2IL5v6EQ5I/w631-h658-no/Capture.PNG Basic List blocks]

=={{header|Apex}}==
<lang apex>Integer[] array = new Integer[10]; // optionally, append a braced list of Integers like "{1, 2, 3}"
array[0] = 42;
System.debug(array[0]); // Prints 42</lang>
Dynamic arrays can be made using <code>List</code>s. <code>List</code>s and array can be used interchangeably in Apex, e.g. any method that accepts a <code>List<String></code> will also accept a <code>String[]</code>
<lang apex>List <Integer> aList = new List <Integer>(); // optionally add an initial size as an argument
aList.add(5);// appends to the end of the list
aList.add(1, 6);// assigns the element at index 1
System.debug(list[0]); // Prints 5, alternatively you can use list.get(0)</lang>


=={{header|AppleScript}}==
=={{header|AppleScript}}==
Line 1,336: Line 1,339:
% There is no automatic garbage collection
% There is no automatic garbage collection
delete $arr
delete $arr
</lang>

=={{header|Boo}}==
<lang boo>
myArray as (int) = (1, 2, 3) // Size based on initialization
fixedArray as (int) = array(int, 1) // Given size(1 in this case)

myArray[0] = 10

myArray = myArray + fixedArray // Append arrays

print myArray[0]
</lang>
</lang>


Line 1,365: Line 1,380:
9
9
mytable is gone</pre>
mytable is gone</pre>

=={{header|Boo}}==
<lang boo>
myArray as (int) = (1, 2, 3) // Size based on initialization
fixedArray as (int) = array(int, 1) // Given size(1 in this case)

myArray[0] = 10

myArray = myArray + fixedArray // Append arrays

print myArray[0]
</lang>


=={{header|Brainf***}}==
=={{header|Brainf***}}==
Line 1,597: Line 1,600:
</lang>
</lang>


=={{header|ChucK}}==
=={{header|C sharp}}==

<lang c>
int array[0]; // instantiate int array
Example of array of 10 int types:

array << 1; // append item
<lang csharp> int[] numbers = new int[10];</lang>
array << 2 << 3; // append items

4 => array[3]; // assign element(4) to index(3)
5 => array.size; // resize
Example of array of 3 string types:

array.clear(); // clear elements
<lang csharp> string[] words = { "these", "are", "arrays" };</lang>
<<<array.size()>>>; // print in cosole array size

[1,2,3,4,5,6,7] @=> array;
You can also declare the size of the array and initialize the values at the same time:
array.popBack(); // Pop last element

</lang>
<lang csharp> int[] more_numbers = new int[3]{ 21, 14 ,63 };</lang>


For Multi-Dimensional arrays you declare them the same except for a comma in the type declaration.

The following creates a 3x2 int matrix
<lang csharp> int[,] number_matrix = new int[3,2];</lang>

As with the previous examples you can also initialize the values of the array, the only difference being each row in the matrix must be enclosed in its own braces.

<lang csharp> string[,] string_matrix = { {"I","swam"}, {"in","the"}, {"freezing","water"} };</lang>

or

<lang csharp> string[,] funny_matrix = new string[2,2]{ {"clowns", "are"} , {"not", "funny"} };</lang>

<lang csharp>int[] array = new int[10];

array[0] = 1;
array[1] = 3;

Console.WriteLine(array[0]);</lang>

Dynamic

<lang csharp>using System;
using System.Collections.Generic;

List<int> list = new List<int>();

list.Add(1);
list.Add(3);

list[0] = 2;

Console.WriteLine(list[0]);</lang>


=={{header|C++}}==
=={{header|C++}}==
Line 1,666: Line 1,705:
demonstrate(dynamic_array);
demonstrate(dynamic_array);
}</lang>
}</lang>

=={{header|C sharp}}==

Example of array of 10 int types:

<lang csharp> int[] numbers = new int[10];</lang>

Example of array of 3 string types:

<lang csharp> string[] words = { "these", "are", "arrays" };</lang>

You can also declare the size of the array and initialize the values at the same time:

<lang csharp> int[] more_numbers = new int[3]{ 21, 14 ,63 };</lang>


For Multi-Dimensional arrays you declare them the same except for a comma in the type declaration.

The following creates a 3x2 int matrix
<lang csharp> int[,] number_matrix = new int[3,2];</lang>

As with the previous examples you can also initialize the values of the array, the only difference being each row in the matrix must be enclosed in its own braces.

<lang csharp> string[,] string_matrix = { {"I","swam"}, {"in","the"}, {"freezing","water"} };</lang>

or

<lang csharp> string[,] funny_matrix = new string[2,2]{ {"clowns", "are"} , {"not", "funny"} };</lang>

<lang csharp>int[] array = new int[10];

array[0] = 1;
array[1] = 3;

Console.WriteLine(array[0]);</lang>

Dynamic

<lang csharp>using System;
using System.Collections.Generic;

List<int> list = new List<int>();

list.Add(1);
list.Add(3);

list[0] = 2;

Console.WriteLine(list[0]);</lang>


=={{header|Ceylon}}==
=={{header|Ceylon}}==
Line 1,738: Line 1,728:
print(list);
print(list);
}</lang>
}</lang>

=={{header|ChucK}}==
<lang c>
int array[0]; // instantiate int array
array << 1; // append item
array << 2 << 3; // append items
4 => array[3]; // assign element(4) to index(3)
5 => array.size; // resize
array.clear(); // clear elements
<<<array.size()>>>; // print in cosole array size
[1,2,3,4,5,6,7] @=> array;
array.popBack(); // Pop last element
</lang>


=={{header|Clean}}==
=={{header|Clean}}==
Line 2,151: Line 2,154:
gotcha: [1, 2, 4]
gotcha: [1, 2, 4]
</pre>
</pre>



=={{header|Déjà Vu}}==
In Déjà Vu, the relevant datatype is called list, which is basically a stack with random element access for getting and setting values.
<lang dejavu>#create a new list
local :l []

#add something to it
push-to l "Hi"

#add something else to it
push-to l "Boo"

#the list could also have been built up this way:
local :l2 [ "Hi" "Boo" ]

#this prints 2
!print len l

#this prints Hi
!print get-from l 0

#this prints Boo
!print pop-from l
</lang>


=={{header|Delphi}}==
=={{header|Delphi}}==
Line 2,255: Line 2,232:
var x = xs[2]
var x = xs[2]
xs[2] = x * x</lang>
xs[2] = x * x</lang>

=={{header|Déjà Vu}}==
In Déjà Vu, the relevant datatype is called list, which is basically a stack with random element access for getting and setting values.
<lang dejavu>#create a new list
local :l []

#add something to it
push-to l "Hi"

#add something else to it
push-to l "Boo"

#the list could also have been built up this way:
local :l2 [ "Hi" "Boo" ]

#this prints 2
!print len l

#this prints Hi
!print get-from l 0

#this prints Boo
!print pop-from l
</lang>


=={{header|E}}==
=={{header|E}}==
Line 3,478: Line 3,479:
ALIAS(Astat, n-1, last2ofAstat, 2)
ALIAS(Astat, n-1, last2ofAstat, 2)
WRITE(ClipBoard) last2ofAstat ! 2.22222222 0 </lang>
WRITE(ClipBoard) last2ofAstat ! 2.22222222 0 </lang>

=={{header|i}}==
<lang i>main
//Fixed-length arrays.
f $= array.integer[1]()
f[0] $= 2
print(f[0])

//Dynamic arrays.
d $= list.integer()
d[+] $= 2
print(d[1])
}</lang>


=={{header|HolyC}}==
=={{header|HolyC}}==
Line 3,610: Line 3,598:
</lang>
</lang>
{{improve|Unicon|Need code examples for these extensions}}
{{improve|Unicon|Need code examples for these extensions}}

=={{header|i}}==
<lang i>main
//Fixed-length arrays.
f $= array.integer[1]()
f[0] $= 2
print(f[0])

//Dynamic arrays.
d $= list.integer()
d[+] $= 2
print(d[1])
}</lang>


=={{header|Io}}==
=={{header|Io}}==
Line 4,014: Line 4,015:


</lang>
</lang>




=={{header|Liberty BASIC}}==
=={{header|Liberty BASIC}}==
Line 4,526: Line 4,525:
true
true
).</lang>
).</lang>

=={{header|MIPS Assembly}}==
<lang mips>
.data
array: .word 1, 2, 3, 4, 5, 6, 7, 8, 9 # creates an array of 9 32 Bit words.

.text
main: la $s0, array
li $s1, 25
sw $s1, 4($s0) # writes $s1 (25) in the second array element
# the four counts thi bytes after the beginning of the address. 1 word = 4 bytes, so 4 acesses the second element
lw $s2, 20($s0) # $s2 now contains 6
li $v0, 10 # end program
syscall
</lang>


=={{header|MiniScript}}==
=={{header|MiniScript}}==
Line 4,575: Line 4,557:
arr.push "x"
arr.push "x"
print arr.pop</lang>
print arr.pop</lang>

=={{header|MIPS Assembly}}==
<lang mips>
.data
array: .word 1, 2, 3, 4, 5, 6, 7, 8, 9 # creates an array of 9 32 Bit words.

.text
main: la $s0, array
li $s1, 25
sw $s1, 4($s0) # writes $s1 (25) in the second array element
# the four counts thi bytes after the beginning of the address. 1 word = 4 bytes, so 4 acesses the second element
lw $s2, 20($s0) # $s2 now contains 6
li $v0, 10 # end program
syscall
</lang>


=={{header|Modula-2}}==
=={{header|Modula-2}}==
Line 5,037: Line 5,036:
);
);
</lang>
</lang>

=={{header|Perl 6}}==
At its most basic, an array in Perl 6 is quite similar to an array in Perl 5.

<lang perl6>my @arr;
push @arr, 1;
push @arr, 3;
@arr[0] = 2;
say @arr[0];</lang>

===Some further exposition:===

In Perl 6, arrays have a very specific definition: "A collection of Scalar containers that do the Positional Role." Scalar container means it is mutable and may contain any object; an Integer, a Rational number, a String, another Array, whatever... literally any other object that can be instantiated in Perl 6. The Positional Role means that it uses integer indexing for access. The index must be a positive integer, an expression that evaluates to a positive integer, or something that can be coerced to a positive integer. Arrays are always indexed from 0. The starting index can not be changed.

Arrays are unconstrained by default. They may hold any number of any type of object up to available memory. They do not need to be pre-allocated. Simply assigning (or even referring in some cases) to an index slot is enough to autovivify the container and allocate enough memory to hold the assigned object. Memory will automatically be allocated and will grow and shrink as necessary to hold the values assigned.

Values may be pushed onto the end of an array, popped off of the end, shifted off of the front or unshifted onto the front, and spliced into or out of the interior.
@array.push: 'value';
my $value = @array.pop;
@array.unshift: 'value';
my $value = @array.shift;
@array.splice(2,3, <some arbitrary string values>);

Arrays may be constrained to only accept a certain number of objects or only a certain type of object.
my Int @array; # can only hold Integer objects. Assigning any other type will cause an exception.
my @array[9]; # can only 10 objects (zero indexed). Trying to assign to an index greater than 9 with cause an exception.

Arrays are constructed with square brackets, an explicit constructor, or by coercing some other object either explicitly using a coercer or implicitly by simply assigning to an array variable. These are all arrays:
[1, 2, 3, 4]
['a', 'b', 'c', 'd']
Array.new<this is an array of words>
('as', 'is', 'this').Array
my @implicit = <yep, this too>

Array variables in Perl 6 are variables whose names bear the @ sigil, and are expected to contain some sort of list-like object. Of course, other variables may also contain these objects, but @-sigiled variables always do, and are expected to act the part. Array storage slots are accessed through postcircumfix square bracket notation. Unlike Perl 5, @-sigiled variables are invariant on access, whether you are accessing one slot, many slots, or all of the slots. The first slot in @array is @array[0] not $array[0]. @array and $array are two different unconnected variables.
@array[1] # a single value in the 2nd slot
@array[*-1] # a single value in the last slot
@array[1..5] # an array slice, 2nd through 6th slots
@array[1,3,7] # slice, 2nd, 4th and 8th slot
@array[8,5,2] # can be in any order
@array[*] # all the slots
@array[] # all the slots (zen slice)
@array[^10] # first 10 slots (upto 10 or 0..9)
@array.head(5) # first 5 slots
@array.tail(2) # last two

Multi-dimensioned arrays also use postcircumfix square brackets for access. If the array is not ragged, (every sub array is the same size) you may use semicolon subscripting.
@array[1][1] # 2nd item in the second slot
@array[1;1] # same thing, implies rectangular (non-ragged) arrays

There are several objects that have an Iterable Role and a PositionalBindFailover Role which makes them act similar to arrays and allows them to be used nearly interchangeably in read-only applications. (Perl 6 is big on duck typing. "If it looks like a duck and quacks like a duck and waddles like a duck, it's a duck.") These constructs are ordered and use integer indexing and are often used in similar circumstances as arrays, however, '''they are immutable'''. Values in slots can not be changed. They can not be pushed to, popped from or spliced. They can easily converted to arrays by simply assigning them to an array variable.

'''List''': A fixed Iterable collection of immutable values. Lists are constructed similarly to arrays:
(1, 2, 3, 4)
('a', 'b', 'c', 'd')
List.new(<this is a list of words>)
('as', 'is', 'this').List
my @not-a-list = (<oops, this isn't>)
my @implicit := (<but this is>) # note the values are bound := not assigned =

'''Range''': Iterable list of consecutive numbers or strings with a lower and an upper boundary. (That boundary may be infinite.) Reified on demand.
2..20 # integers two through twenty
1..Inf # natural numbers
'a'..'z' # lowercase latin letters
'⁰'..'⁹' # superscript digits

'''Sequence''': Iterable list of objects with some method to determine the next (or previous) item in the list. Reified on demand. Will try to automatically deduce simple arithmetic or geometric sequences. Pass in a code object to calculate more complex sequences.
0,2,4 ... 64 # even numbers up to 64
1,2,4 ... 64 # geometric increase
1,1, *+* ... * # infinite Fibonacci sequence
1,1,{$^n2 + $^n1 + 1} ... * # infinite Leonardo numbers

Postcircumfix indexing works for any object that has a Positional (or PositionalBindFailover) role, it need not be in a @-sigiled variable, or indeed, in a variable at all.
[2,4,6,8,10][1] # 4 - anonymous array
<my dog has fleas>[*-2] # 'has' - anonymous list
sub a {(^Inf).grep: *.is-prime}; a()[99]; # 541 - (100th prime) subroutine returning a sequence
my $lol = ((1,2), (3,4), (5,6)); $lol[1]; # (3 4) - list of lists in a Scalar variable


=={{header|Phix}}==
=={{header|Phix}}==
Line 5,400: Line 5,319:
x 1 get
x 1 get
</lang>
</lang>

=={{header|PowerShell}}==
=={{header|PowerShell}}==
Empty array:
Empty array:
Line 5,579: Line 5,499:
(gvector-add! gv 5) ; increase size
(gvector-add! gv 5) ; increase size
</lang>
</lang>

=={{header|Raku}}==
(formerly Perl 6)
At its most basic, an array in Perl 6 is quite similar to an array in Perl 5.

<lang perl6>my @arr;
push @arr, 1;
push @arr, 3;
@arr[0] = 2;
say @arr[0];</lang>

===Some further exposition:===

In Perl 6, arrays have a very specific definition: "A collection of Scalar containers that do the Positional Role." Scalar container means it is mutable and may contain any object; an Integer, a Rational number, a String, another Array, whatever... literally any other object that can be instantiated in Perl 6. The Positional Role means that it uses integer indexing for access. The index must be a positive integer, an expression that evaluates to a positive integer, or something that can be coerced to a positive integer. Arrays are always indexed from 0. The starting index can not be changed.

Arrays are unconstrained by default. They may hold any number of any type of object up to available memory. They do not need to be pre-allocated. Simply assigning (or even referring in some cases) to an index slot is enough to autovivify the container and allocate enough memory to hold the assigned object. Memory will automatically be allocated and will grow and shrink as necessary to hold the values assigned.

Values may be pushed onto the end of an array, popped off of the end, shifted off of the front or unshifted onto the front, and spliced into or out of the interior.
@array.push: 'value';
my $value = @array.pop;
@array.unshift: 'value';
my $value = @array.shift;
@array.splice(2,3, <some arbitrary string values>);

Arrays may be constrained to only accept a certain number of objects or only a certain type of object.
my Int @array; # can only hold Integer objects. Assigning any other type will cause an exception.
my @array[9]; # can only 10 objects (zero indexed). Trying to assign to an index greater than 9 with cause an exception.

Arrays are constructed with square brackets, an explicit constructor, or by coercing some other object either explicitly using a coercer or implicitly by simply assigning to an array variable. These are all arrays:
[1, 2, 3, 4]
['a', 'b', 'c', 'd']
Array.new<this is an array of words>
('as', 'is', 'this').Array
my @implicit = <yep, this too>

Array variables in Perl 6 are variables whose names bear the @ sigil, and are expected to contain some sort of list-like object. Of course, other variables may also contain these objects, but @-sigiled variables always do, and are expected to act the part. Array storage slots are accessed through postcircumfix square bracket notation. Unlike Perl 5, @-sigiled variables are invariant on access, whether you are accessing one slot, many slots, or all of the slots. The first slot in @array is @array[0] not $array[0]. @array and $array are two different unconnected variables.
@array[1] # a single value in the 2nd slot
@array[*-1] # a single value in the last slot
@array[1..5] # an array slice, 2nd through 6th slots
@array[1,3,7] # slice, 2nd, 4th and 8th slot
@array[8,5,2] # can be in any order
@array[*] # all the slots
@array[] # all the slots (zen slice)
@array[^10] # first 10 slots (upto 10 or 0..9)
@array.head(5) # first 5 slots
@array.tail(2) # last two

Multi-dimensioned arrays also use postcircumfix square brackets for access. If the array is not ragged, (every sub array is the same size) you may use semicolon subscripting.
@array[1][1] # 2nd item in the second slot
@array[1;1] # same thing, implies rectangular (non-ragged) arrays

There are several objects that have an Iterable Role and a PositionalBindFailover Role which makes them act similar to arrays and allows them to be used nearly interchangeably in read-only applications. (Perl 6 is big on duck typing. "If it looks like a duck and quacks like a duck and waddles like a duck, it's a duck.") These constructs are ordered and use integer indexing and are often used in similar circumstances as arrays, however, '''they are immutable'''. Values in slots can not be changed. They can not be pushed to, popped from or spliced. They can easily converted to arrays by simply assigning them to an array variable.

'''List''': A fixed Iterable collection of immutable values. Lists are constructed similarly to arrays:
(1, 2, 3, 4)
('a', 'b', 'c', 'd')
List.new(<this is a list of words>)
('as', 'is', 'this').List
my @not-a-list = (<oops, this isn't>)
my @implicit := (<but this is>) # note the values are bound := not assigned =

'''Range''': Iterable list of consecutive numbers or strings with a lower and an upper boundary. (That boundary may be infinite.) Reified on demand.
2..20 # integers two through twenty
1..Inf # natural numbers
'a'..'z' # lowercase latin letters
'⁰'..'⁹' # superscript digits

'''Sequence''': Iterable list of objects with some method to determine the next (or previous) item in the list. Reified on demand. Will try to automatically deduce simple arithmetic or geometric sequences. Pass in a code object to calculate more complex sequences.
0,2,4 ... 64 # even numbers up to 64
1,2,4 ... 64 # geometric increase
1,1, *+* ... * # infinite Fibonacci sequence
1,1,{$^n2 + $^n1 + 1} ... * # infinite Leonardo numbers

Postcircumfix indexing works for any object that has a Positional (or PositionalBindFailover) role, it need not be in a @-sigiled variable, or indeed, in a variable at all.
[2,4,6,8,10][1] # 4 - anonymous array
<my dog has fleas>[*-2] # 'has' - anonymous list
sub a {(^Inf).grep: *.is-prime}; a()[99]; # 541 - (100th prime) subroutine returning a sequence
my $lol = ((1,2), (3,4), (5,6)); $lol[1]; # (3 4) - list of lists in a Scalar variable


=={{header|REBOL}}==
=={{header|REBOL}}==
Line 5,819: Line 5,820:
└────────────────────────────────────────────────────────────────────┘*/
└────────────────────────────────────────────────────────────────────┘*/
/*stick a fork in it, we're done.*/</lang>
/*stick a fork in it, we're done.*/</lang>

=={{header|Ring}}==

Dynamic

<lang ring># create an array with one string in it
a = ['foo']

# add items
a + 1 # ["foo", 1]

# set the value at a specific index in the array
a[1] = 2 # [2, 1]

# retrieve an element
see a[1]</lang>


=={{header|RLaB}}==
=={{header|RLaB}}==
Line 5,854: Line 5,871:


</lang>
</lang>

=={{header|RPG}}==

{{works with|ILE RPG}}

<lang rpg>
//-Static array
//--def of 10 el array of integers, initialised to zeros
D array...
D s 10i 0 dim(10)
D inz
//--def an el
D el_1...
D s 10i 0 inz
/free
//-assign first el
//--first element of RPG array is indexed with 1
array(1) = 111;
//-get first el of array
el_1 = array(1);
//--display it
dsply ('First el of array='+%char(el_1));
//--displays: First el of array=111

//---or shorter, without "el_1"
dsply ('First el of array='+%char(array(1)));
//--displays: First el of array=111
/end-free
</lang>


=={{header|Ring}}==

Dynamic

<lang ring># create an array with one string in it
a = ['foo']

# add items
a + 1 # ["foo", 1]

# set the value at a specific index in the array
a[1] = 2 # [2, 1]

# retrieve an element
see a[1]</lang>


=={{header|Robotic}}==
=={{header|Robotic}}==
Line 5,939: Line 5,905:


Because arrays aren't built in, there are no functions that allow you to manipulate the data you create within an array. You would have to create your own function when, for example, you want to sort numbers from least to greatest.
Because arrays aren't built in, there are no functions that allow you to manipulate the data you create within an array. You would have to create your own function when, for example, you want to sort numbers from least to greatest.

=={{header|RPG}}==

{{works with|ILE RPG}}

<lang rpg>
//-Static array
//--def of 10 el array of integers, initialised to zeros
D array...
D s 10i 0 dim(10)
D inz
//--def an el
D el_1...
D s 10i 0 inz
/free
//-assign first el
//--first element of RPG array is indexed with 1
array(1) = 111;
//-get first el of array
el_1 = array(1);
//--display it
dsply ('First el of array='+%char(el_1));
//--displays: First el of array=111

//---or shorter, without "el_1"
dsply ('First el of array='+%char(array(1)));
//--displays: First el of array=111
/end-free
</lang>


=={{header|Ruby}}==
=={{header|Ruby}}==
Line 5,964: Line 5,964:
# retrieve an element
# retrieve an element
puts a[0]</lang>
puts a[0]</lang>

=={{header|Run BASIC}}==
=={{header|Run BASIC}}==
<lang runbasic>print "Enter array 1 greater than 0"; : input a1
<lang runbasic>print "Enter array 1 greater than 0"; : input a1
Line 6,197: Line 6,198:
# retrieve an element
# retrieve an element
say arr[-1]; #=> 'baz'</lang>
say arr[-1]; #=> 'baz'</lang>

=={{header|Simula}}==
=={{header|Simula}}==
<lang simula>BEGIN
<lang simula>BEGIN
Line 6,968: Line 6,970:
</lang>
</lang>


=={{header|Vim Script}}==
Lists can be used for dynamic arrays. Indexing starts at 0.
<lang vim>" Creating a dynamic array with some initial values
let array = [3, 4]

" Retrieving an element
let four = array[1]

" Modifying an element
let array[0] = 2

" Appending a new element
call add(array, 5)

" Prepending a new element
call insert(array, 1)

" Inserting a new element before another element
call insert(array, 3, 2)

echo array</lang>

{{Out}}
<pre>[1, 2, 3, 4, 5]</pre>
=={{header|VBA}}==
=={{header|VBA}}==
<lang vb>Sub matrix()
<lang vb>Sub matrix()
Line 7,024: Line 7,002:
{{out}}
{{out}}
<pre> 1 4 9 1 4 9 1 4 9 16 </pre>
<pre> 1 4 9 1 4 9 1 4 9 16 </pre>
=={{header|Visual Basic .NET}}==
<lang vbnet>'Example of array of 10 int types:
Dim numbers As Integer() = New Integer(0) {}
'Example of array of 4 string types:
Dim words As String() = {"hello", "world", "from", "mars"}
'You can also declare the size of the array and initialize the values at the same time:
Dim more_numbers As Integer() = New Integer(2) {21, 14, 63}

'For Multi-Dimensional arrays you declare them the same except for a comma in the type declaration.
'The following creates a 3x2 int matrix
Dim number_matrix As Integer(,) = New Integer(2, 1) {}


'As with the previous examples you can also initialize the values of the array, the only difference being each row in the matrix must be enclosed in its own braces.
Dim string_matrix As String(,) = {{"I", "swam"}, {"in", "the"}, {"freezing", "water"}}
'or
Dim funny_matrix As String(,) = New String(1, 1) {{"clowns", "are"}, {"not", "funny"}}

Dim array As Integer() = New Integer(9) {}
array(0) = 1
array(1) = 3
Console.WriteLine(array(0))


'Dynamic
Imports System
Imports System.Collections.Generic
Dim list As New List(Of Integer)()
list.Add(1)
list.Add(3)
list(0) = 2
Console.WriteLine(list(0))</lang>


=={{header|VHDL}}==
=={{header|VHDL}}==
Line 7,117: Line 7,063:
end architecture Example;
end architecture Example;
</lang>
</lang>

=={{header|Vim Script}}==
Lists can be used for dynamic arrays. Indexing starts at 0.
<lang vim>" Creating a dynamic array with some initial values
let array = [3, 4]

" Retrieving an element
let four = array[1]

" Modifying an element
let array[0] = 2

" Appending a new element
call add(array, 5)

" Prepending a new element
call insert(array, 1)

" Inserting a new element before another element
call insert(array, 3, 2)

echo array</lang>

{{Out}}
<pre>[1, 2, 3, 4, 5]</pre>

=={{header|Visual Basic .NET}}==
<lang vbnet>'Example of array of 10 int types:
Dim numbers As Integer() = New Integer(0) {}
'Example of array of 4 string types:
Dim words As String() = {"hello", "world", "from", "mars"}
'You can also declare the size of the array and initialize the values at the same time:
Dim more_numbers As Integer() = New Integer(2) {21, 14, 63}

'For Multi-Dimensional arrays you declare them the same except for a comma in the type declaration.
'The following creates a 3x2 int matrix
Dim number_matrix As Integer(,) = New Integer(2, 1) {}


'As with the previous examples you can also initialize the values of the array, the only difference being each row in the matrix must be enclosed in its own braces.
Dim string_matrix As String(,) = {{"I", "swam"}, {"in", "the"}, {"freezing", "water"}}
'or
Dim funny_matrix As String(,) = New String(1, 1) {{"clowns", "are"}, {"not", "funny"}}

Dim array As Integer() = New Integer(9) {}
array(0) = 1
array(1) = 3
Console.WriteLine(array(0))


'Dynamic
Imports System
Imports System.Collections.Generic
Dim list As New List(Of Integer)()
list.Add(1)
list.Add(3)
list(0) = 2
Console.WriteLine(list(0))</lang>


=={{header|Wee Basic}}==
=={{header|Wee Basic}}==
Line 7,291: Line 7,295:


print a$(5) // show the content of an element of the array. Now is empty</lang>
print a$(5) // show the content of an element of the array. Now is empty</lang>

=={{header|zonnon}}==
<lang pascal>
var
a: array 10 of integer;
da: array * of cardinal;
</lang>


=={{header|zkl}}==
=={{header|zkl}}==
Line 7,306: Line 7,303:
array[3] //-->4
array[3] //-->4
array+9; //append a 9 to the end, same as array.append(9)</lang>
array+9; //append a 9 to the end, same as array.append(9)</lang>

=={{header|zonnon}}==
<lang pascal>
var
a: array 10 of integer;
da: array * of cardinal;
</lang>


=={{header|ZX Spectrum Basic}}==
=={{header|ZX Spectrum Basic}}==