Ada Language Fundamentals




Example 0: sayhi.adb

 
   -- Simple Ada program
   --   in file sayhi.adb

   with Ada.Text_IO;

   procedure sayHi is
   begin
      Ada.Text_IO.put("Hi!");    -- Output some text!
   end sayHi;
        


Program Structure



Comments



Program Structure



Package Ada.Text_IO



With Statement



Use Statement



Identifiers and Case Sensitivity



Literals


Example 1: Table of Squares and Cubes



Assignment Statement



Assignment in Java and C



Initialization

     
         with ada.integer_text_io;
         procedure initialize is
            data1: Integer;
         begin 
             put(data1);
         end initialize;


Constants



For Loop Statement



Three Kinds of Loops



Loop and a Half



Named Loops



If Statements



Case Statement - Multiway Selection



Case Statement - Multiple-Value Selection

      -- Ada:
      case i is 
         when 4|3 => put_line("****");
         when 2|1 => put_line("**");
         when others => null;
      end case;

      // Java 
      switch (i){
        case 4: 
        case 3: System.out.println("****"); break;
        case 2:
        case 1: System.out.println("**"); break;
        default: ;
        } // End of break
  


Common Java Errors Avoided



Example Program



Integer'Image - An Attribute of type Integer



Package Ada.Integer_Text_IO



Integer Types



Floating Point Types



Package Ada.Float_Text_IO



Primitive Types



Types and Type Checking



Explicit Type Conversion



Implicit and Explicit Type Conversion



Operators: Precedence and Associativity



Examples using Arithmetic Operators



Rem and Mod Operators



Examples using Relational and Boolean Operators



Example using String Concatenation Operator

        put_line("Hello, this certainly is a "
                & "really long line!");
        

Short Circuit: and then, or else


in Membership Test

 
        if i in 1 .. 10 then