标题案例使用枚举 IO 为子范围

字符大小写的变化Enumeration_IO相结合并为图像使用文本缓冲区。第一个角色被操作到位。

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Characters.Handling; use Ada.Characters.Handling;

procedure Main is
    type Fruit is (Banana, Pear, Orange, Melon);
    package Fruit_IO is new Enumeration_IO (Fruit);
    Buffer : String (1 .. Fruit'Width);
begin
   for I in Fruit range Pear .. Fruit'Last loop
       Fruit_IO.Put (To => Buffer,
                     Item => I,
                     Set => Lower_Case);
       Buffer (Buffer'First) := To_Upper (Buffer (Buffer'First));
       Put_Line (Buffer);
   end loop;
end;

结果

Pear  
Orange
Melon