Ada Programming/Keywords/for
This keyword is used in:
- For loops
- Representation clauses:
- attribute definition clause
- enumeration representation clause
- record representation clause
- at clause (obsolescent)
- Quantified expressions
- Universal quantification
- Existential quantification
Nowadays representation clauses are formally called aspect clauses in the last versions of the Reference Manual due to some technicalities, although representation clauses is the name far more extended among Ada programmers. As a historical note, they were known as representation specifications (rep specs) in pre-Ada 83 proposals.[1]
For loops
[edit | edit source][loop name :]for
varin
[reverse
] [typerange
] rangeloop
...end
loop
[loop name];
Where range can be:
- explicit range like "
low .. high
", - range of scalar or array type:
type'Range
(ortype'Range(n)
for multidimensional array types) - range of an array:
array'Range (or array'Range(n)
for multidimensional arrays)
Keyword in
may also be followed by an iterable. This generalizes iteration by including types that have one of the interfaces defined in Ada.Iterator_Interfaces.
This language feature has been introduced in Ada 2012.
Another generalized form of looping iteration uses the keyword of
in place of in
. The loop parameter is then referring to components of arrays or of iterable container types, directly.
This language feature has been introduced in Ada 2012.
[loop name :]for
var [: type]of
[reverse
] iterableloop
...end
loop
[loop name];
Representation clauses
[edit | edit source]The keywords for
, use
and at
are used for representation clauses.
A record representation clause specifies the Layout aspect of a record.
An enumeration representation clause specifies the Coding aspect of an enumeration type.
See Ada Programming/Representation_clauses.
Quantified expressions
[edit | edit source]This language feature has been introduced in Ada 2012.
Quantified expressions are Boolean expressions. They are either True or False, or propagate any exception raised during evaluation.
Universal quantification
[edit | edit source]Universal quantification expression:
(for
all
varin
range => predicate) (for
all
varof
iterable => predicate)
Both forms evaluate to True when all of the values in range (of iterable) make the predicate yield True. Evaluation of predicate stops when either all values of loop parameter var have been exhausted, or when evaluation for some value yields False (short circuit).
Existential quantification
[edit | edit source]Existential quantification expression:
(for
some
varin
range => predicate) (for
some
varof
iterable => predicate)
Both forms evaluate to True when some of the values in range (of iterable) makes the predicate yield True. Evaluation of predicate stops when either all values of loop parameter var have been exhausted, or when evaluation for some value yields True (short circuit).
See also
[edit | edit source]Wikibook
[edit | edit source]Ada Reference Manual
[edit | edit source]- 2.9 Reserved Words (Annotated)
- Annex P (informative) Syntax Summary (Annotated)
- 5.5 Loop Statements (Annotated)
- 13.3 Operational and Representation Attributes (Annotated)
- 13.4 Enumeration Representation Clauses (Annotated)
- 13.5.1 Record Representation Clauses (Annotated)
- Annex J.7 At Clauses (Annotated) (obsolescent)
Ada 83
[edit | edit source]- 13.5: Address Clauses (obsolescent)
Ada Quality and Style Guide
[edit | edit source]References
[edit | edit source]- ↑ John Barnes (2003-03-25). High-Integrity Software — The SPARK Approach to Safety and Security. Addison-Wesley. ISBN 0-321-13616-0. Retrieved 2008-06-06.
Representation clauses are now strictly known as aspect clauses — the name was changed in the 2000 Corrigendum for Ada 95 for subtle reasons that need not concern us; Ada historians might recall that they were known as representation specifications (rep specs) prior to the ANSI standardization in 1983. These various terminologies are all in use and the reader will encounter them in the literature. (pp.212–213)
Ada Keywords | ||||
---|---|---|---|---|
abort
|
else
|
new
|
return
|
|
abs
|
elsif
|
not
|
reverse
|
|
abstract (Ada 95)
|
end
|
null
|
||
accept
|
entry
|
select
|
||
access
|
exception
|
of
|
separate
|
|
aliased (Ada 95)
|
exit
|
or
|
some (Ada 2012)
|
|
all
|
others
|
subtype
|
||
and
|
for
|
out
|
synchronized (Ada 2005)
|
|
array
|
function
|
overriding (Ada 2005)
|
||
at
|
tagged (Ada 95)
|
|||
generic
|
package
|
task
|
||
begin
|
goto
|
parallel (Ada 2022)
|
terminate
|
|
body
|
pragma
|
then
|
||
if
|
private
|
type
|
||
case
|
in
|
procedure
|
||
constant
|
interface (Ada 2005)
|
protected (Ada 95)
|
until (Ada 95)
|
|
is
|
use
|
|||
declare
|
raise
|
|||
delay
|
limited
|
range
|
when
|
|
delta
|
loop
|
record
|
while
|
|
digits
|
rem
|
with
|
||
do
|
mod
|
renames
|
||
requeue (Ada 95)
|
xor
|