-- Programmer:  Elizabeth Adams

-- CS 430

-- October 4, 2004

-- Environment:  Windows 98 2nd Edition

-- Compiler :  GNAT (used jGrasp IDE)

--

-- Source:  testLCV.adb

-- Executable:  testLCV.exe

-- Purpose: the purpose of this program is to verify the behavior

--          of Ada's fixed iteration loop

-- Input : none

-- Output: values of the loop control variables

with Ada.Text_IO;   -- include library package for reading/writing characters/strings

with Ada.Integer_Text_IO; -- include library package for reading/writing integers

with Ada.Float_Text_IO; -- include library package for reading/writing floats

procedure testLCV is  -- procedure body header

type color is (red, green, blue);  -- defining a new enumerated type

--package myIntIo is new Ada.text_io.integer_io (item => integer);----

package color_IO is new Ada.text_IO.Enumeration_IO (Enum => color); -- instantiation

j : integer;

a : float;

begin

j := 5;

for i in 1..3 loop  -- #1 integer type LCV

   Ada.Integer_Text_IO.put (i);

-- i := 27;  -- #3  testlcv.adb:26:09: assignment to loop parameter not allowed

 

end loop;

-- Ada.Integer_Text_IO.put (i);  --   #2,#4  testlcv.adb:28:27: "i" is undefined

 

 Ada.text_io.new_line;

j := 5;

for i in 1..j loop    -- #5  modifying upper bound within loop

   Ada.Integer_Text_IO.put (i);

      j := 17;  -- note that loop executes exactly 5 times

      Ada.Text_IO.new_line;

end loop;

 

for i in reverse 8..j loop  -- #7  iteration backwards

   Ada.Integer_Text_IO.put (i);

end loop;  

 

Ada.Text_IO.new_line(2);

for x in color'first..color'last loop  -- #1 enumerated type

   color_io.put (item=> x, width => 10);

--    Ada.Text_IO.put ("  "); -- alternative for spacing

end loop;

 

Ada.text_io.new_line;

for x in 1..10 loop

  Ada.Integer_Text_IO.put (item => x);

  if x = 3 then

      exit;  -- #10 jumping out of loop possible

  end if;

end loop;

 

Ada.text_io.new_line;

for letter in Character'Succ('a') .. Character'Pred('j') loop --#1 Character

  Ada.Text_IO.put (letter);

end loop;

 

Ada.text_io.new_line;

for y in false..true loop -- #1  boolean LCV

  if (y) then

     Ada.Text_IO.put_line (" y has value true");

  else

     Ada.Text_IO.put_line (" y has value false");

  end if;    

end loop;

 

a := 53.79;

Ada.text_IO.new_line;

--for a in 1.5 .. 2.4 loop -- #1  trying float LCV 

                           -- testlcv.adb:72:14: expected a discrete type

                           -- testlcv.adb:72:14: found type universal real

  Ada.Float_Text_IO.put (a);

  Ada.text_IO.new_line;

  Ada.Float_Text_IO.put (item => a, fore => 7, aft => 2, exp => 0);

 

end testLCV;