pragma Ada_2012;
-- Demonstrates various ways of looping and various attributes
-- Why are these important?
with ada.text_io; use ada.text_io;
procedure array_loops is
-- An UNCONSTRAINED array type
type My_U_Array_T is array(Natural range <>) of Character;
-- Different sizes, same named type
a4: My_U_Array_T(2 .. 5) := (others => 'x');
a5: My_U_Array_T(12 .. 25) := (12 .. 15 | 17 => 'a', others => 'z');
begin
for i in a4'range loop
put(a4(i));
end loop;
new_line;
for i in a4'first .. a4'last loop
put(a4(i));
end loop;
new_line;
for i in a4'first .. a4'first + a4'length - 1 loop
put(a4(i));
end loop;
new_line;
for a of a4 loop -- Iterator is a Ada 2012 feature
put(a);
end loop;
new_line;
for a of a4 loop -- Iterator allows changing the value
a := Character'succ(a); -- Successor of 'x' is 'y'
end loop;
for a of a4 loop -- Outputs all 'y'
put(a);
end loop;
new_line;
end array_loops;
-- Output:
--|xxxx
--|xxxx
--|xxxx
--|xxxx
--|yyyy