5.5 Loop Statements
Syntax
Static Semantics
Dynamic Semantics
Ramification: The order of creating the
loop parameter and evaluating the
discrete_subtype_definition
doesn't matter, since the creation of the loop parameter has no side
effects (other than possibly raising Storage_Error, but anything can
do that).
{
AI05-0262-1}
The predicate (if any) necessarily has to be a
static predicate as a dynamic predicate is explicitly disallowed —
see 3.2.4.
Reason:
{
AI05-0262-1}
If there is a predicate, the loop still visits
the values in the order of the underlying base type; the order of the
values in the predicate is irrelevant. This is the case so that the following
loops have the same sequence of calls and parameters on procedure Call
for any subtype S:
for I in S loop
Call (I);
end loop;
for I in S'Base loop
if I in S then
Call (I);
end if;
end loop;
8 The
discrete_subtype_definition
of a for loop is elaborated just once. Use of the reserved word
reverse
does not alter the discrete subtype defined, so that the following
iteration_schemes
are not equivalent; the first has a null range.
for J in reverse 1 .. 0
for J in 0 .. 1
Examples
Example of a loop
statement without an iteration scheme:
loop
Get(Current_Character);
exit when Current_Character = '*';
end loop;
Example of a
loop statement with a while iteration scheme:
while Bid(N).Price < Cut_Off.Price loop
Record_Bid(Bid(N).Price);
N := N + 1;
end loop;
Example of a
loop statement with a for iteration scheme:
for J in Buffer'Range loop -- works even with a null range
if Buffer(J) /= Space then
Put(Buffer(J));
end if;
end loop;
Example of a
loop statement with a name:
Summation:
while Next /= Head
loop --
see 3.10.1
Sum := Sum + Next.Value;
Next := Next.Succ;
end loop Summation;
Wording Changes from Ada 83
Wording Changes from Ada 2005
Ada 2005 and 2012 Editions sponsored in part by Ada-Europe