2.1. Declaration - JulTob/Ada GitHub Wiki

All variables have to be declared before use. To declare a variable is to set a name (or identificator) for it and a type as follows:

procedure Example is

-- Variables go here in is..begin
Variable : Type;  --In the declarative part (before begin)
Const_Variable : constant Type;  --For constant parameters

-- Declaration with initialization
Value : Integer := 42

begin
-- ... --

A variable can only have values from it’s type’s set.

The declaration determines the scope.

We also declared the use of a library so we can use implicit scoping inside the function. Without it we should apply explicit scoping, as follows:

 Simple_IO.Get(x);
 Simple_IO.Put(sqrt(x));

Get allows us to read input from console, and Out to write in console.

Another program Example:

with Sqrt, Simple_IO;    --Call to libraries

procedure Print_Root is
  use Simple_IO;
  X: float;
begin 
   Put(“Roots of Input number”);
   New_Line(2);
   loop 
      Get(X);
      exit when X = 0.0;
      Put(“ Root of ); Put(X); Put(“ is “);
      if X < 0.0 then
         Put(“not calculable”);
      else
         Put(Sqrt(X));
      end if;
      New_Line;
   end loop 
   New_Line;
   Put(“Program finished”);
   New_Line;
end Print_Root;