-- Demonstrates 
--      constrained arrays with anonymous types
--      array attributes: 'first, 'last, 'range, 'length
--      a subtype as a range
--      an array iterator

with ada.text_io; use ada.text_io;
with ada.integer_text_io; use ada.integer_text_io;

procedure array1 is
    subtype animal_range is Integer range -3 .. 3;

    cat_count: array(animal_range) of Natural := (-3 | -1 | 1 | 3 => 1, others => 0);
    dog_count: array(animal_range) of Natural := (-2 |  0 | 2     => 1, others => 0);
    animal_count: array(animal_range) of Natural;

    total_dogs, total_cats, total_animals: Natural := 0;
begin
    for i in cat_count'first .. cat_count'last loop  -- -3 .. 3
        total_cats := total_cats + cat_count(i);
    end loop;

    for i in dog_count'range loop                    -- -3 .. 3
        total_dogs := total_dogs + dog_count(i);
    end loop;

    for i in animal_range loop                       -- -3 .. 3
        animal_count(i) := cat_count(i) + dog_count(i);
    end loop;

    -- Iterate through values of animal_count.   Notice "of".
    for a of animal_count loop
        total_animals := total_animals + a;
    end loop;
    put_line(total_animals'img);

end array1;

-- Output:
--| 7