DEV Community

Discussion on: Fibonacci in Every Language

Collapse
 
pinotattari profile image
Riccardo Bernardini

Ada (unfortunately seems that no syntax highlighting is available for Ada)

with Ada.Command_Line;
with Ada.Text_IO; use Ada.Text_IO;

use Ada;

procedure Fib is
   Old   : Natural := 1;
   Older : Natural := 0;
   Limit : Positive;
   Tmp   : Positive;

   Bad_Command_Line : exception; 
begin 
   if Command_Line.Argument_Count /= 1 Then
      raise Bad_Command_Line;
   end if;

   Limit := Positive'Value (Command_Line.Argument (1));

   for K in 1..Limit Loop
      Put_Line (Standard_Error, Integer'Image (K) & ":" & Integer'Image(Old));
      Tmp := Old + Older;
      Older := Old;
      Old := Tmp;
   end loop;
exception
   when Bad_Command_Line | Constraint_Error => 
      Put_Line(Standard_Error, 
               "Usage : Please Input The Count of Fibonacci Numbers To Output");

      Command_Line.Set_Exit_Status(Command_Line.Failure);
end Fib;