-- Eratosthenes Sieve Prime Number Program
-- in Augusta

Procedure Prime is
  prime,K,count : integer;
  flags   : array(8190) of boolean;

Begin
  putline("10 iterations");
  for iter in 1..10
  loop
    count := 0;
    flags(0) := true; -- initialize the array
    moveleft ( @flags(0), @flags(1), 16378);
    for I in 0..8190
    loop
      if flags(I) then
        prime := I + I + 3;
        K := I + prime;
        while K <= 8190
        loop
          flags(K) := false;
          K := K + prime;
        end loop;
        count := count + 1;
--      putstr("Prime #=");
--      putint(prime);
--      newline;
      end if;
    end loop;
  end loop;
  putint(count); putline(" primes");
End;
