Learn Ada - 10 Code Examples & CST Typing Practice Test
Ada is a statically typed, high-level programming language designed for safety-critical, real-time, and concurrent systems. Developed with reliability and maintainability in mind, Ada emphasizes strong typing, modularity, exception handling, and support for concurrent programming.
Learn ADA with Real Code Examples
Updated Nov 20, 2025
Code Sample Descriptions
Ada Counter and Theme Toggle
with Ada.Text_IO; use Ada.Text_IO;
procedure Counter is
Count : Integer := 0;
Is_Dark : Boolean := False;
procedure Update_UI is
begin
Put_Line("Counter: " & Integer'Image(Count));
Put_Line("Theme: " & (if Is_Dark then "Dark" else "Light"));
end Update_UI;
begin
-- Initial display
Update_UI;
-- Increment counter
Count := Count + 1;
Update_UI;
-- Increment counter again
Count := Count + 1;
Update_UI;
-- Toggle theme
Is_Dark := not Is_Dark;
Update_UI;
-- Decrement counter
Count := Count - 1;
Update_UI;
-- Reset counter
Count := 0;
Update_UI;
end Counter;
Demonstrates a simple counter with theme toggling using Ada variables and console output.
Ada Simple Addition
with Ada.Text_IO; use Ada.Text_IO;
procedure Add is
A, B, Sum : Integer;
begin
A := 10;
B := 20;
Sum := A + B;
Put_Line("Sum: " & Integer'Image(Sum));
end Add;
Adds two numbers and prints the result.
Ada Factorial
with Ada.Text_IO; use Ada.Text_IO;
procedure Factorial is
function Fact(N: Integer) return Integer is
begin
if N <= 1 then
return 1;
else
return N * Fact(N-1);
end if;
end Fact;
begin
Put_Line("Factorial 5: " & Integer'Image(Fact(5)));
end Factorial;
Calculates factorial recursively.
Ada Fibonacci Sequence
with Ada.Text_IO; use Ada.Text_IO;
procedure Fibonacci is
function Fib(N: Integer) return Integer is
begin
if N < 2 then
return N;
else
return Fib(N-1) + Fib(N-2);
end if;
end Fib;
begin
for I in 0..9 loop
Put_Line(Integer'Image(Fib(I)));
end loop;
end Fibonacci;
Generates first 10 Fibonacci numbers.
Ada Max of Two Numbers
with Ada.Text_IO; use Ada.Text_IO;
procedure Max_Num is
A, B, Max : Integer;
begin
A := 10;
B := 20;
if A > B then
Max := A;
else
Max := B;
end if;
Put_Line("Max: " & Integer'Image(Max));
end Max_Num;
Finds the maximum of two numbers.
Ada List Sum
with Ada.Text_IO; use Ada.Text_IO;
procedure List_Sum is
Arr : array(1..5) of Integer := (1,2,3,4,5);
Sum : Integer := 0;
begin
for I in Arr'Range loop
Sum := Sum + Arr(I);
end loop;
Put_Line("Sum: " & Integer'Image(Sum));
end List_Sum;
Sums elements of an array.
Ada Even Numbers Filter
with Ada.Text_IO; use Ada.Text_IO;
procedure Even_Filter is
Arr : array(1..5) of Integer := (1,2,3,4,5);
begin
for I in Arr'Range loop
if Arr(I) mod 2 = 0 then
Put_Line(Integer'Image(Arr(I)));
end if;
end loop;
end Even_Filter;
Prints even numbers from an array.
Ada Conditional Counter Increment
with Ada.Text_IO; use Ada.Text_IO;
procedure Conditional_Increment is
Count : Integer := 3;
begin
if Count < 5 then
Count := Count + 1;
end if;
Put_Line("Count: " & Integer'Image(Count));
end Conditional_Increment;
Increment counter only if less than 5.
Ada Resettable Counter
with Ada.Text_IO; use Ada.Text_IO;
procedure Resettable_Counter is
Count : Integer := 0;
begin
Count := Count + 1;
Count := Count + 1;
Put_Line("Count: " & Integer'Image(Count));
Count := 0;
Put_Line("Count: " & Integer'Image(Count));
end Resettable_Counter;
Counter that increments and can be reset.
Ada Theme Toggle Only
with Ada.Text_IO; use Ada.Text_IO;
procedure Theme_Toggle_Only is
Is_Dark : Boolean := False;
begin
Put_Line("Theme: " & (if Is_Dark then "Dark" else "Light"));
Is_Dark := not Is_Dark;
Put_Line("Theme: " & (if Is_Dark then "Dark" else "Light"));
Is_Dark := not Is_Dark;
Put_Line("Theme: " & (if Is_Dark then "Dark" else "Light"));
end Theme_Toggle_Only;
Toggles theme multiple times.
Frequently Asked Questions about Ada
What is Ada?
Ada is a statically typed, high-level programming language designed for safety-critical, real-time, and concurrent systems. Developed with reliability and maintainability in mind, Ada emphasizes strong typing, modularity, exception handling, and support for concurrent programming.
What are the primary use cases for Ada?
Safety-critical avionics systems. Real-time embedded software. Railway signaling and control. Defense and military software. Medical device software. High-integrity systems requiring formal verification
What are the strengths of Ada?
High reliability and maintainability. Excellent support for concurrent and real-time systems. Compile-time type safety reduces runtime errors. Modular design encourages clean architecture. Widely used in certified, high-integrity systems
What are the limitations of Ada?
Steep learning curve for beginners. Less community support compared to mainstream languages. Verbose syntax relative to modern scripting languages. Smaller ecosystem of libraries for general-purpose programming. Not ideal for rapid prototyping or casual applications
How can I practice Ada typing speed?
CodeSpeedTest offers 10+ real Ada code examples for typing practice. You can measure your WPM, track accuracy, and improve your coding speed with guided exercises.