-- Demonstrates that arrays have relational and equality operators
-- Must have same named type
-- Does element by element comparison
with ada.text_io; use ada.text_io;
procedure arrays_compare is
s1: String := "cabs";
s2: String := "cat";
s3: String := "catenate";
type My_Array_T is array(Natural range <>) of Integer;
t1: My_Array_T(1 .. 5) := (4 => 8, others => 1);
t2: My_Array_T(1 .. 5) := (4 => 9, others => 1);
t3: My_Array_T(1 .. 6) := (others => 1);
begin
-- All of the ifs are true
if s1 < s2 then put_line("s1 < s2"); end if;
if s2 < s3 then put_line("s2 < s3"); end if;
if s2 = s3(1 .. 3) then put_line("s2 = s3(1 .. 3)"); end if;
if t1 < t2 then put_line("t1 < t2"); end if;
if t1 /= t2 then put_line("t1 /= t2"); end if;
if t1 = (1, 1, 1, 8, 1) then put_line("t1 = (1,1,1,4,1)"); end if;
if t1 > t3 then put_line("t1 > t3"); end if;
end arrays_compare;
-- Output:
-- s1 < s2
-- s2 < s3
-- s2 = s3(1 .. 3)
-- t1 < t2
-- t1 /= t2
-- t1 = (1,1,1,4,1)
-- t1 > t3