8
Statements
[stmt]
8.6
Iteration statements
[stmt.iter]
8.6.1
General
[stmt.iter.general]
1
#
Iteration statements specify looping
.
iteration-statement
:
while
(
condition
)
statement
do
statement
while
(
expression
)
;
for
(
init-statement
condition
o
p
t
;
expression
o
p
t
)
statement
for
(
init-statement
o
p
t
for-range-declaration
:
for-range-initializer
)
statement
[
Note
1
:
An
init-statement
ends with a semicolon
.
—
end note
]
2
#
The substatement in an
iteration-statement
implicitly defines a block
scope
which is entered and exited each time through the loop
.
If the substatement in an
iteration-statement
is a single statement and not a
compound-statement
, it is as if it was rewritten to be a
compound-statement
containing the original statement
.
[
Example
1
:
while
(
-
-
x
>
=
0
)
int
i;
can be equivalently rewritten as
while
(
-
-
x
>
=
0
)
{
int
i;
}
Thus after the
while
statement,
i
is no longer in scope
.
—
end example
]
3
#
A
trivially empty iteration statement
is an iteration statement matching one of the following forms:
(3.1)
while
(
expression
)
;
(3.2)
while
(
expression
)
{
}
(3.3)
do
;
while
(
expression
)
;
(3.4)
do
{
}
while
(
expression
)
;
(3.5)
for
(
init-statement
expression
o
p
t
;
)
;
(3.6)
for
(
init-statement
expression
o
p
t
;
)
{
}
The
controlling expression
of a trivially empty iteration statement is the
expression
of a
while
,
do
, or
for
statement (or
true
, if the
for
statement has no
expression
)
.
A
trivial infinite loop
is a trivially empty iteration statement for which the converted controlling expression is a constant expression, when interpreted as a
constant-expression
(
[expr.
const.
const]
), and evaluates to
true
.
The
statement
of a trivial infinite loop is replaced with a call to the function
std
::
this_
thread
::
yield
(
[thread.
thread.
this]
); it is
implementation-defined whether this replacement occurs on freestanding implementations
.
[
Note
2
:
In a freestanding environment, concurrent forward progress is not guaranteed; such systems therefore require explicit cooperation
.
A call to yield can add implicit cooperation where none is otherwise intended
.
—
end note
]