Ada · Lesson 1 · On the house

Program structure and output

with clauses, procedure bodies, Put_Line, and building with gnatmake. Lesson 1 is free — on the house.

Lessons · Ada · Lesson 1 of 10 · On the house

Program structure and output

with clauses, procedure bodies, Put_Line, and building with gnatmake.

Illustration for Ada
Lesson 1 is on the house.

An Ada main program is a parameterless procedure: procedure Hello is begin ... end Hello;.

with Ada.Text_IO; makes a library package available; use Ada.Text_IO; lets you drop the prefix.

Put prints without a newline, Put_Line with one, New_Line prints a bare newline.

Build and run with GNAT: gnatmake hello.adb && ./hello. The file name should match the unit name in lowercase.

Ada is case-insensitive; comments start with --. Statements end with ;.

hello

with Ada.Text_IO; use Ada.Text_IO;

procedure Hello is
begin
   Put_Line ("Hello from Ada");
   Put ("same ");
   Put ("line");
   New_Line;
   Ada.Text_IO.Put_Line ("fully qualified call");
end Hello;
Match this when you type.

Quiz

What is an Ada main program?

Quiz

What does with Ada.Text_IO; do?

Quiz

Which call prints without a newline?

Quiz

How do comments start?

Check

Match the still for: Program structure and output.

Open-book: the answers are on this page. Pass every quiz and check (5) to mark the lesson done. This visit: 0/5.