Q:

How to loop through multiple data sets from standard input

I am reading from standard input (a text file and doing calculations with the data which is lined up like this:
 2 --This states the amount of following sets of info
 150 -- this is the first set of data
 250 -- this is the second set of data
 0 -- this is supposed to tell my program that this is the end of the two sets but
      keep looping because there might be multiple sets in here, seperated by "0"'s.  

Basic outline of my ADA program: 
procedure test is

begin 

  while not end_of_file loop
  ......//my whole program executes

  end loop;
end test; 

I want to know how to tell my program to keep looping until theres nothing to read but to keep in mind that the ZERO's seperate the data sets and to keep looping if there is more data after each "0".  

A:

I think this program would meet your requirement, with no need to exit loops prematurely:
with Ada. Integer_Text_Io; use Ada. Integer_Text_Io;
with Ada. Text_Io; use Ada. Text_Io;

procedure Reading_Data is
begin
   while not End_Of_File loop
      declare
         Number_Of_Sets : Natural;
      begin
         Get (Number_Of_Sets);
         if Number_Of_Sets > 0 then
            declare
               Sum : Integer := 0;
            begin
               for J in 1 .. Number_Of_Sets loop
                  declare
                     Tmp : Integer;
                  begin
                     Get (Tmp);
                     Sum := Sum + Tmp;
                  end;
               end loop;
               Put ("sum of");
               Put (Number_Of_Sets);
               Put (" elements is ");
               Put (Sum);
               New_Line;
            end;
         end if;
      end;
   end loop;
end Reading_Data;

However, it doesn’t need the 0 separator between sets; 0 just means “this is a set with no elements, ignore it”. 
Now, if this a reduced example from a problem where you need to check data consistency (i.e. if you promised 2 elements, then after reading the 2 elements you are either at end of file or there’s a 0) this solution wouldn’t be right. ( And you might think I’ve gone overboard with the declare blocks to minimise the scope of the variables ...)
With input:
1
10
0
2
20 30
3 40 50 60

the program gives output:
sum of          1 elements is          10
sum of          2 elements is          50
sum of          3 elements is         150

