Arrays: Difference between revisions

664 bytes added ,  21 days ago
m
imported>Arakov
 
(2 intermediate revisions by 2 users not shown)
Line 730:
<syntaxhighlight lang="ada">procedure Array_Test is
 
A,type BExample_Array_Type :is array (1..20) of Integer;
A, B : Example_Array_Type;
 
-- Ada array indices may begin at any value, not just 0 or 1
C : array (-37..20) of integerInteger;
 
-- Ada arrays may be indexed by enumerated types, which are
Line 756 ⟶ 757:
Centered : Arr (-50..50) := (0 => 1, Others => 0);
 
Result : Integer;
begin
 
A := (others => 0); -- Assign whole array
B := (1 => 1, 2 => 1, 3 => 2, others => 0);
-- Assign whole array, different values
A (1) := -1; -- Assign individual element
Line 766 ⟶ 767:
A (3..5) := (2, 4, -1); -- Assign a constant slice
A (3..5) := A (4..6); -- It is OK to overlap slices when assigned
 
Fingers_Extended(Fingers'First) := False; -- Set first element of array
Fingers_Extended(Fingers'Last) := False; -- Set last element of array
 
end Array_Test;</syntaxhighlight>
Line 3,238 ⟶ 3,239:
Dynamic array
<syntaxhighlight lang="elena"> var dynamicArray := new system'collections'ArrayList();
dynamicArray.append:(1);
dynamicArray.append:(2);
dynamicArray.append:(4);
 
dynamicArray[2] := 3;</syntaxhighlight>
Line 7,867 ⟶ 7,868:
/end-free
</syntaxhighlight>
 
{{works with|ILE RPG v7.1+}}
<nowiki>**</nowiki>free
//-Static array
//--def of 10 el array of integers, initialised to zeros
dcl-s array int(10) dim(10) inz;
//--def an el
dcl-s el_1 int(10) inz(0);
//-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
 
=={{header|RPL}}==
2

edits