Guide

Step By Step

πŸ“Ί Input and Output ⌨

Get & Put

The two Ada processes for in/out processes are:

  • Put: To put out some data or text.
  • Get: To Get some Data from a source.

By default the Put writes the output in the console. Get reads from the keyboard. This can, of course, be changed to files.

You may be wondering why not just say Input/Output. Because these are relative. A data input for one program is output for another.

Also you may notice is much more elegant than print that some languages use for Put. Where are you printing into? Do I need a printer now?

Put and Get are not defined by default. If you want to call it with a new type you have to build them first, or call with the 'image or 'value attribute.

Nonetheless, most types do have a built in library that you can use to put and get data.

But for general Text In/Out processes, you can use Text_IO. A smart use of 'image is usually sufficient for most cases.

with Ada.Text_IO;

procedure Test is
  A,B,C:Integer;
begin
   A:=Integer'Value(Ada.Text_IO.Get_Line);
   B:=Integer'Value(Ada.Text_IO.Get_Line);
   C:= A + B;

   if C=0 then
      Ada.Text_IO.Put_Line("Result is 0");
   elsif c>0 then
      Ada.Text_IO.
         Put_Line( "Positive result: " 
            & Integer'Image(C));
   else
      Ada.Text_IO.
         Put_Line( "Negative result: " 
            & Integer'Image(C));
   end if;

end Test;