Values in Ada

Values

Ada has various value types including strings, integers, floats, booleans, etc. Here are a few basic examples.

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Float_Text_IO; use Ada.Float_Text_IO;

procedure Main is
begin
    -- Strings, which can be concatenated with "&".
    Put_Line("ada" & "lang");

    -- Integers and floats.
    Put_Line("1+1 = " & Integer'Image(1 + 1));
    Put("7.0/3.0 = ");
    Put(Float(7.0 / 3.0), Fore => 1, Aft => 15, Exp => 0);
    New_Line;

    -- Booleans, with boolean operators as you’d expect.
    Put_Line(Boolean'Image(True and False));
    Put_Line(Boolean'Image(True or False));
    Put_Line(Boolean'Image(not True));
end Main;

To run the program, compile the code with gnatmake Main.adb and then execute it.

$ gnatmake Main.adb
$ ./main
adalang
1+1 =  2
7.0/3.0 =  2.333333333333333
FALSE
TRUE
FALSE

Now that we can run and build basic Ada programs, let’s learn more about the language.