In Ada you can specify which indexes to iterate over:
-- Declarations
Start : Index_Type;
Finish : Index_Type;
-- Usage
Start := -- Pick your start
Finish := -- Pick your end
for Index in Start .. Finish loop
-- do your stuff
end loop;
-- Example
with Ada.Text_IO; use Ada.Text_IO;
procedure Test is
type Index_Type is (Red, Blue, Green);
type Array_Type is array(Index_Type range <>) of Integer;
My_Array : Array_Type(Index_Type'Range) := (1,2,3);
Start, Finish : Index_Type;
begin
Start := Blue;
Finish := Green;
for Index in Start .. Finish loop
Put_Line(My_Array(Index)'Image);
end loop;
Put_Line("Hello World");
end Test;
where Start and End can be any index type you want. Or you can just iterate over all of them if you want and let the compiler determine what the first and last are.
This works for any type that can be an index of an array (Enumerations, Integers, etc.).
For any index type you can do things like:
Index_Type'First
Index_Type'Last
Index_Type'Succ(value)
Index_Type'Pred(value)
My_Array'Length
My_Array'Range
among many others. These should allow you to do what index math you need (again independent of the index type). See some examples below
for Index in My_Array'Range loop
if Index /= My_Array'First then
-- do stuff here
end if;
end loop;
if My_Array'First /= Index_Type'Last then
for Index in Index_Type'Succ(My_Array'First) .. My_Array'Last loop
-- Do your stuff
end loop;
end if;