with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Text_IO; use Ada.Text_IO;
procedure tryArrays4 is
s: string(1..10) := "abcdefghij";
m, n: Integer;
Type MyArray is array (1 .. 10) of Integer;
a: MyArray := (11, 12, 13, 14, 15, 16, 17, 18, 19, 20);
b: MyArray := (81, 82, 83, 84, 85, 86, 87, 88, 89, 90);
begin
-- String slice: We've seen this
put_line( s(2 .. 5) );
-- Slice bounds can be dynamic
m := 3;
n := 5;
put_line( s(m .. n) );
-- Can access and assign a slice
a(2 .. 4) := (-1, -2, -3);
-- Warning of runtime error if aggregate is wrong size
for i in a'range loop
put(a(i), width=>4);
end loop;
new_line;
-- Initialize a slice
a(1 .. 3) := a(8 .. 10);
for i in 1..10 loop
put(a(i), width=>4);
end loop;
new_line;
-- Shift with overlapping slices:
a(1 .. 9) := a(2 .. 10);
for i in a'range loop
put(a(i), width=>4);
end loop;
new_line;
-- Types on both sides of assignment must be identical
a(1 .. 3) := b; -- Compiles but warns of runtime error
a(1 .. 3) := b(1..3); -- Okay
end tryArrays4;
-- SAMPLE RUN
bcde
cde
11 -1 -2 -3 15 16 17 18 19 20
18 19 20 -3 15 16 17 18 19 20
19 20 -3 15 16 17 18 19 20 20