--  Verada's `while` clause (T25b, stream-combinators.md 6.3): the iteration ends at the first
--  element (that passed the filter) for which it is false; in reductions and loops.
pragma Extensions_Allowed (On);
with Ada.Text_IO; use Ada.Text_IO;
procedure Main is
   subtype Small is Integer range 0 .. 100;
   type Arr is array (Positive range <>) of Small;

   --  the sum of the leading positive values
   function Prefix (A : Arr) return Integer is
     ([for X of A while X > 0 => X]'Reduce ("+", 0))
   with Pre => A'Length <= 1000;

   --  the even ones among them
   function Even_Prefix (A : Arr) return Integer is
     ([for X of A when X mod 2 = 0 while X > 0 => X]'Reduce ("+", 0))
   with Pre => A'Length <= 1000;

   B : constant Arr := (4, 1, 6, 3, 0, 8, 9);
begin
   Put_Line (Integer'Image (Prefix (B)) & Integer'Image (Even_Prefix (B)));
   for X of B while X > 0 loop
      Put (Integer'Image (X));
   end loop;
   New_Line;
end Main;
