Home

Ada Range Attributes

   

First

with Ada.Text_IO;
use Ada.Text_IO;

procedure Exercise is
   type Genders is (Male, Female, Unknown);

begin
   Put_Line("Gender = " & Genders'image(Genders'First));
end Exercise;

This would produce:

Gender = MALE
   

 

Last

with Ada.Text_IO;
use Ada.Text_IO;

procedure Exercise is
   type Genders is (Male, Female, Unknown);

begin
   Put_Line("Gender = " & Genders'image(Genders'Last));
end Exercise;

This would produce:

Gender = UNKNOWN

Min

with Ada.Text_IO;
use Ada.Text_IO;

procedure Exercise is
   type Names is (John, Raymondo, Gertrude, Anselme, Patricia, Lucius);

begin
   Put_Line("Name = " & Names'image(Names'Min(Raymondo, Anselme)));
end Exercise;

This would produce:

Name = RAYMONDO

Max

with Ada.Text_IO;
use Ada.Text_IO;

procedure Exercise is
   type Names is (John, Raymondo, Gertrude, Anselme, Patricia, Lucius);

begin
   Put_Line("Name = " & Names'image(Names'Max(Raymondo, Anselme)));
end Exercise;

This would produce:

Name = ANSELME

Succ

with Ada.Text_IO;
use Ada.Text_IO;

procedure Exercise is
   type Names is (John, Raymondo, Gertrude, Anselme, Patricia, Lucius);

begin
   Put_Line("Name = " & Names'image(Names'Succ(Names'Min(Raymondo, Anselme))));
end Exercise;

This would produce:

Name = GERTRUDE

Pred

with Ada.Text_IO;
use Ada.Text_IO;

procedure Exercise is
   type Names is (John, Raymondo, Gertrude, Anselme, Patricia, Lucius);

begin
   Put_Line("Name = " & Names'image(Names'Pred(Names'Min(Raymondo, Anselme))));
end Exercise;

This would produce:

Name = JOHN

 

 

 

 

 

 
 
 
 
 
   
 

Home Copyright © 2010-2016, FunctionX