Skip to main content
CodeSpeedTest
Languages
Start TypingJump into a test — pick any languageAdaptive TrainingUnlock chars as you master themPractice DrillsFocused sessions targeting weak spotsDaily ChallengesNew coding challenges every dayRace ModeCompete against others in real timeAI OpponentRace against an AI at your WPM levelTournamentsLive coding speed tournamentsArcade GamesZType, Overkill Survival, Glyphica & moreGamificationXP, coins, badges & quests
LeaderboardGlobal rankings for every languageCertificatesEarn verifiable Bronze / Silver / Gold certsActivityDaily streaks & historical analyticsProfileYour stats, badges & achievements
Browse Languages500+ languages with real code examplesBlogTips, guides & deep divesFree ToolsWPM calculator, typing speed report & moreFAQCommon questions answeredGetting StartedNew to CodeSpeedTest?AboutOur story & missionSupportGet help — Pro users get priorityContactGet in touch with the team
Pricing
  1. Home
  2. /
  3. Learn
  4. /
  5. Ada

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.

View all 10 Ada code examples →
Ada Counter and Theme ToggleAda Simple AdditionAda FactorialAda Fibonacci SequenceAda Max of Two NumbersAda List SumAda Even Numbers FilterAda Conditional Counter IncrementAda Resettable CounterAda Theme Toggle Only

Learn ADA with Real Code Examples

Updated Nov 20, 2025

Explain

Ada supports structured, object-oriented, and concurrent programming paradigms.

It is widely used in aerospace, defense, transportation, and other safety-critical systems.

Its compiler enforces strict type checking, which reduces runtime errors and improves reliability.

Core Features

Procedures, functions, and packages

Tasking and protected types for concurrency

Generics for reusable code

Exception handling

Strong typing and subtyping

Basic Concepts Overview

Strong typing and variable declarations

Procedures and functions

Packages and modularity

Tasking and concurrency

Exception handling

Project Structure

source.adb (body)

source.ads (specification)

packages/

tests/

Makefiles or GNAT project files (.gpr)

Building Workflow

Write `.adb` and `.ads` files

Compile with `gnatmake` or IDE build tools

Run executable

Debug using GNAT debugger or IDE

Unit test critical routines

Difficulty Use Cases

Beginner: Hello World, basic arithmetic

Intermediate: modular packages, file IO

Advanced: real-time concurrent tasks

Expert: safety-critical avionics/defense systems

Comparisons

More robust than C/C++ for safety-critical systems

Less flexible for rapid scripting than Python or Ruby

Concurrency model safer than traditional threads

Strong typing prevents many runtime errors

Better for certified systems than general-purpose languages

Versioning Timeline

1979 - Ada design commissioned by DoD

1983 - Ada 83 standard released

1995 - Ada 95 introduced object-oriented features

2005 - Ada 2005 added real-time and concurrency enhancements

2012 - Ada 2012 added contract-based programming

Glossary

Task: concurrent unit of execution

Package: module for encapsulation

Protected Type: concurrency-safe data type

Exception: runtime error handling mechanism

SPARK: subset of Ada for formal verification

Installation Setup

Install GNAT Ada compiler (part of GCC) or AdaCore IDE

Verify compiler installation with `gnatmake --version`

Set up project directory with source files

Write test program (Hello World in Ada)

Compile and run using `gnatmake`

Environment Setup

Install GNAT Ada compiler

Set PATH for GNAT binaries

Optional: Install AdaCore GPS IDE

Create project directories

Compile and run sample program

Config Files

.gpr GNAT project file

Source `.adb` and `.ads` files

Makefiles or build scripts

SPARK verification files

Configuration for target RTOS

Cli Commands

gnatmake main.adb # compile

gnat bind main.ali # link

./main # run executable

gnatprove # SPARK verification

gnatls # list compiled units

Internationalization

UTF-8 strings supported

Locale-specific formats possible

I18N requires external libraries

Text_IO supports basic character encoding

Used globally in safety-critical industries

Accessibility

GNAT compiler error messages

IDE support via GPS

Documentation from AdaCore

Tutorials and sample code

Community forums

Ui Styling

Primarily console-based

GUI via bindings to external libraries

No native web UI support

Output formatting via Text_IO

Embedded system outputs for devices

State Management

Variables with explicit types

Task-local state

Protected types for concurrency

Exception handling state

Shared state via task synchronization

Data Management

Strongly typed variables

Arrays and records

Modular packages for data encapsulation

I/O via Ada.Text_IO

Concurrent access via protected types

Architecture

Strongly typed language with static checking

Supports procedural, object-oriented, and concurrent programming

Tasking model for concurrent execution

Package-based modularity

Compile-time verification of contracts and invariants

Rendering Model

Source code compiled to native binary

Static type checks at compile-time

Tasking model handles concurrency safely

Packages encapsulate functionality

Compile-time contracts enforce design rules

Architectural Patterns

Modular package-based design

Tasking for concurrent systems

Protected types for shared data

Design-by-contract with pre/post conditions

High-integrity real-time patterns

Real World Architectures

Avionics flight software

Railway control systems

Defense mission-critical applications

Medical device software

Embedded real-time controllers

Design Principles

Safety and reliability first

Strong static typing

Support for modular and maintainable code

Concurrency with tasking and protected types

Formal verification support via SPARK

Scalability Guide

Modularize using packages

Use tasking for concurrent operations

Minimize global variables

Leverage generics for reusable code

Apply contract-based programming for robustness

Migration Guide

Move legacy embedded C code to Ada for safety-critical applications

Convert modules to packages

Use SPARK for formal verification

Adapt concurrency to tasking model

Refactor exception handling for safety

Performance Notes

Compiled native code runs efficiently

Tasking allows fine-grained concurrency

Use protected types to avoid race conditions

Optimize loops and data structures for real-time systems

Minimize dynamic memory allocation in critical tasks

Security Notes

Strong typing prevents common runtime errors

Use exceptions for controlled error handling

Concurrency safeguards prevent data races

Validate inputs in safety-critical modules

Follow standards for certified software (DO-178C, ISO 26262)

Monitoring Analytics

Debug logs for tasks

Runtime exception handling

Profiling via compiler tools

Formal verification results

Unit and integration testing

Code Quality

Follow strong typing conventions

Use packages and modular design

Test tasking and concurrency thoroughly

Document exception handling

Apply formal verification with SPARK when applicable

Practical Examples

Hello World console program

Concurrent producer-consumer tasks

Embedded system sensor interface

Railway signal control logic

Flight software for avionics

Troubleshooting

Check for type mismatches

Verify package and procedure visibility

Debug tasking and synchronization issues

Check for missing `.ads` or `.adb` files

Use compiler warnings for potential issues

Testing Guide

Unit tests for procedures/functions

Test tasking and concurrent code

Verify exception handling paths

Use SPARK tools for formal verification

Regression tests for critical modules

Deployment Options

Compile to native executables

Integrate with RTOS for embedded systems

Deploy on avionics or transportation hardware

Use SPARK-certified code for safety-critical software

Generate static libraries for reuse

Tools Ecosystem

GNAT Ada compiler (GCC-based)

AdaCore GPS/IDE

SPARK Ada tools for formal verification

GPRbuild for project management

Debugger: GDB or GNAT Debugger

Integrations

Embedded hardware interfaces

Real-time operating systems

Formal verification tools (SPARK)

Interfacing with C libraries

Aerospace and defense system toolchains

Productivity Tips

Use packages for modularity

Follow strict naming conventions

Test tasks and concurrency carefully

Leverage SPARK for verification

Use Makefiles or GNAT project files to automate builds

Challenges

Write Hello World program

Create modular packages

Implement concurrent producer-consumer tasks

Develop a simple embedded system interface

Simulate real-time control system logic

Learning Path

Learn Ada syntax and strong typing

Understand procedures, functions, and packages

Explore tasking and concurrency

Practice exception handling

Apply Ada to real-time and embedded systems

Skill Improvement Plan

Week 1: Basic syntax, variables, and procedures

Week 2: Packages, modularity, and type system

Week 3: Tasking, concurrency, and protected types

Week 4: Exception handling and real-time programming

Interview Questions

Explain Ada’s strong typing system.

What are packages and how are they used?

Describe tasking and concurrency in Ada.

How does Ada handle exceptions?

What is the role of SPARK Ada in verification?

Cheat Sheet

with Ada.Text_IO; use Ada.Text_IO;

procedure Main is

begin Put_Line('Hello World');

end Main;

task type Worker is ... end Worker;

Books

Programming in Ada 2012

Ada 95: The Craft of Object-Oriented Programming

SPARK 2014 Language Reference

Tutorials

Learn Ada Programming with GNAT

Ada for Real-Time Systems

SPARK Ada Basics

Official Docs

Ada Reference Manual

AdaCore GNAT User Guide

SPARK Ada Verification Guide

Community Links

AdaCore Community Forum

StackOverflow Ada tag

Reddit r/ada

Community Support

AdaCore Community

StackOverflow Ada tag

Reddit r/ada

Comp.lang.ada newsgroup

Embedded and aviation forums

Monetization

Defense and aerospace contracts

Medical device software development

Railway and transportation control systems

Consulting in real-time and safety-critical systems

High-integrity software engineering services

Future Roadmap

Maintain relevance in safety-critical industries

Improved compiler optimizations

Enhanced SPARK verification integration

Better IDE and tooling support

Continued use in avionics, defense, and embedded systems

When Not To Use

Rapid prototyping or scripting

Casual web development

GUI-heavy desktop apps

Games and graphics-intensive apps

Machine learning with extensive libraries

Final Summary

Ada is a high-integrity, strongly typed language for safety-critical and real-time systems.

Ideal for avionics, defense, transportation, and embedded applications.

Its strict typing, modularity, and concurrency features make it reliable and maintainable.

Ada continues to be relevant in certified, mission-critical software development.

Faq

Is Ada still used today?

Yes - in aerospace, defense, railways, and other safety-critical industries.

Can Ada handle concurrency?

Yes - Ada provides tasking and protected types.

Is Ada suitable for beginners?

It has a steep learning curve but excellent for safety-critical programming.

Does Ada support object-oriented programming?

Yes - Ada supports OOP with tagged types and inheritance.

Code Sample Descriptions

1

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.

Let’s Try →
2

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.

Let’s Try →
3

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.

Let’s Try →
4

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.

Let’s Try →
5

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.

Let’s Try →
6

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.

Let’s Try →
7

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.

Let’s Try →
8

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.

Let’s Try →
9

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.

Let’s Try →
10

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.

Let’s Try →

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.

Learn Other Programming Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypherGremlinPartiqlHaskellElixirFsharpView all languages →
CodeSpeedTest

Improve your coding speed, code accuracy, and programming syntax WPM with practice sessions across 500+ programming languages.

Quick Links

HomeAboutFeaturesGetting StartedLanguages

Legal & Support

Pro ⚡ PricingContactPrivacy PolicyTerms of Service

Connect

CodeSpeedTest on GitHubCodeSpeedTest on TwitterEmail CodeSpeedTest

© 2026 CodeSpeedTest. All rights reserved.