



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An introduction to ada programming, focusing on visibility rules, loops, and functions. It covers the concept of direct visibility, loop control variables, nested loops, scalar types, and functions. Examples and exercises to help readers understand these concepts.
Typology: Slides
1 / 5
This page cannot be seen from the preview
Don't miss anything!




with
Fact; procedure
Main
is
procedure
Hello
is
begin
Ada.Text_Io.Put(“Hello”); end
Hello;
begin
for
in
1 .. Fact (4)
loop
Hello; end loop; end
Main;
function
Fact (N : Integer)
return
Integer
is
begin
if^
then return
else
return
N * Fact (N-1);
end if; end
Fact;
with
Fact;
Main
is Hello
is
begin
Ada.Text_Io.Put(“Hello”); end
Hello;
begin
for
in
1 .. Fact (4)
loop
Hello; end loop; end
Main;
function
Fact (N : Integer)
return
Integer
is
begin
if^
return
return
N * Fact (N-1);
end if; end
Fact;
time through the loop.
The loop
variable = upper bound, then the loop terminates.
for
<
loop_control_variable
^
in
<
lower_bound
..<
upper_bound
^
loop
< loop_body
;
procedure
procedure
then
else
This is the name of the "variable that controls the loop".The loop control variable is incremented by one eachThe initial value given to the loop control variable.The final value of the loop control variable.body
executes
one
more
time
when
the
loop
control
The code that's executed each time through the loop.
end loop
function
return
is
function
Fact
Integer)
return
Integer
is
begin
if
then return
else
return
Fact
end
if;
end
Fact;
No Information Flow (No Parameters) procedure
is
procedure
... )
is with
Ada.Text_IO;
use
Ada.Text_IO;
procedure
Hello
is
begin
Put_Line (“Hello”);
end
Hello; with
Ada.Text_IO;
use
Ada.Text_IO;
procedure
Increment (X :
in out
Integer;
Y :
in out
float)
is
begin
x:= x + 1; y := y + 1.4; end
Hello;
contains the function name and parameters.variables used in the function (but nowhere else).the code the function executes.the name of the function. contains the procedure name and parameters.variables used in the procedure (but nowhere else).the code the procedure executes.the name of the procedure.
With Information Flow (With Parameters)
:
:
No Parameters
... );
with
Hello;
procedure
Main
is
begin
Hello; end
Main;
with
Increment;
procedure
Main
is
my_x
integer
my_y
float
begin
Increment(my_x,
my_y);
end
Main;
type
int_8_array
(1 .. 8)
of
Integer;
type
CUBE
(1..6, 1..6, 1..6)
of
Integer;
for
in
loop
for
in
loop
Put
type My_Type_Record isrecord
my_integer : Integer;my_real
: Float;
end record;
type My_Other_Type_Record isrecord
my_integer : Integer;my_real
: Float;
end record;
Rec1 : my_type_record;Rec2 : my_other_type_record;
is array
is array
end
loop
end
loop
my_boolean : Boolean;
my_boolean : Boolean;