ARRAYS:
A: array (INTEGER range 1 .. 10) of INTEGER;
for I in 1 .. 10 loop
A(I) := 0;
end loop;
for I in 0 .. 2 loop
for J in 0 .. 3 loop
A2(I,J) := 0;
end loop;
end loop;
— Type declarations
type WEEK_T is (Mon, Tue, Wed, Thu, Fri, Sat, Sun);
subtype WORK_WEEK_T is WEEK_T range Mon .. Fri;
— Variable declarations
Hours_Worked : array (WEEK_T) of INTEGER;
Day : WEEK_T;
for Day in WORK_WEEK_T loop
Hours_Worked(Day) := 8;
endloop;
Hours_Worked(Sat) := 0;
Hours_Worked(Sun) := 0;
— type declaration
type A_T is array (INTEGER range <>) of INTEGER;
subtype A_Sub_T is A_T(1 .. 3)
— Object declaration
My_Var : A_Sub_T;
— On the other hand
My_Var : A_T(1 .. 3);
— Array aggregates
My_Var := ( 1 .. 2 => 10, others => 0);
RECORDS :
type MONTH_NAME_T is
(Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec)
— Record type
type DATE_T is
record
Day : INTEGER range 1 .. 31;
Month : MONTH_NAME_T;
Year : INTEGER;
end record;
— Another record
type EMPLOYEE_T is
record
DOB : DATE_T;
NAME : STRING(1 .. 30) := (1 .. 30 =>’’);
end record;
— Object declaration
PERSON : EMPLOYEE_T;
— Assigning records
PERSON.DOB := (17, Sep, 1975);
PERSON.NAME(1 .. 6) := “Thomas”;
FUNCTIONS:
function MY_F (I : INTEGER) return INTEGER is
J : INTEGER := 0;
begin
J := I;
return J;
end MY_F;
- Functions have to return a value of the return type
- PROGRAM_ERROR
PROCEDURES:
procedure MY_F (I : INTEGER) is
J : INTEGER := 0;
begin
J := I;
end MY_F;
- return;
PACKAGES:
package MY_S is — package specification
procedure MY_P;
end MY_S;
package body MY_S is — package body
procedure MY_P is — a null procedure
begin
null;
end MY_P;
end MY_S;
package MY_S is
function MY_F return BOOLEAN;
end MY_S;
with TEXT_IO;
package body MY_S is
function MY_F return BOOLEAN is separate;
begin
TEXT_IO.PUT_LINE (“This is only the beginning”);
end MY_S;