Summary
This chapter lays the foundations for the small-scale aspects of Ada. We start by considering the declaration of objects and the assignment of values to them and briefly discuss the ideas of scope and visibility. We then introduce the important concepts of type, subtype and constraints. As examples of types, the remainder of the chapter discusses the numeric types Integer and Float, enumeration types in general, the type Boolean in particular, and the operations on them.
Object declarations and assignments
Values can be stored in objects which are declared to be of a specific type. Objects are either variables, in which case their value may change (or vary) as the program executes, or they may be constants, in which case they keep their same initial value throughout their life.
A variable is introduced into the program by a declaration which consists of the name (that is, the identifier) of the variable followed by a colon and then the name of the type. This can then optionally be followed by the := symbol and an expression giving the initial value. The declaration terminates with a semicolon. Thus we might write
J: Integer;
P: Integer := 38;
The first declaration introduces the variable J of type Integer but gives it no particular initial value. The second introduces the variable P and gives it the specific initial value of 38.
- Type
- Chapter
- Information
- Programming in Ada 2012 , pp. 73 - 100Publisher: Cambridge University PressPrint publication year: 2014