5.5 Loop Statements
1
Syntax
2
3/3
4
5
Static Semantics
6
Dynamic Semantics
7
8
9/3
9.a
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).
9.b/3
{
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.
9.1/3
10
11
11.a
12
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.
13
for J in reverse 1 .. 0
for J in 0 .. 1
13.a
Examples
14
Example of a loop
statement without an iteration scheme:
15
loop
Get(Current_Character);
exit when Current_Character = '*';
end loop;
16
Example of a
loop statement with a while iteration scheme:
17
while Bid(N).Price < Cut_Off.Price loop
Record_Bid(Bid(N).Price);
N := N + 1;
end loop;
18
Example of a
loop statement with a for iteration scheme:
19
for J in Buffer'Range loop -- works even with a null range
if Buffer(J) /= Space then
Put(Buffer(J));
end if;
end loop;
20
Example of a
loop statement with a name:
21
Summation:
while Next /= Head
loop --
see 3.10.1
Sum := Sum + Next.Value;
Next := Next.Succ;
end loop Summation;
Wording Changes from Ada 83
21.a
Wording Changes from Ada 2005
21.b/3
Ada 2005 and 2012 Editions sponsored in part by Ada-Europe