在输入后递增数字的任务

用户可以通过按下'0' .. '9'中的一个键来拨打 Incrementor.Increment K 次数,并且可以比 task Incrementor 更快地调用 Incrementor.Increment I

with Ada.Text_IO;
with Ada.Integer_Text_IO;

procedure Main is
   use Ada.Text_IO;
   task Incrementor is
      entry Increment;
   end;
   task body Incrementor is
      use Ada.Integer_Text_IO;
      I : Integer := 0;
   begin
      loop
         accept Increment;
         I := I + 1;
         Put (I, 0);
         delay 0.1;
      end loop;
   end;
   K : Character;
begin
   loop
      Get_Immediate (K);
      if K in '0' .. '9' then
         for I in 1 .. Natural'Value (K & "") loop
            Incrementor.Increment;
         end loop;
      end if;
   end loop;
end;