8
Statements
[stmt.stmt]
8.6
Iteration statements
[stmt.iter]
8.6.2
The
while
statement
[stmt.while]
1
#
In the
while
statement the substatement is executed repeatedly until the value of the condition (
[stmt.
pre]
) becomes
false
.
The test takes place before each execution of the substatement
.
2
#
A
while
statement is equivalent to
label
:
{
if
(
condition
)
{
statement
goto
label
;
}
}
[
Note
1
:
The variable created in the condition is destroyed and created with each iteration of the loop
.
[
Example
1
:
struct
A
{
int
val; A
(
int
i
)
:
val
(
i
)
{
}
~
A
(
)
{
}
operator
bool
(
)
{
return
val
!
=
0
;
}
}
;
int
i
=
1
;
while
(
A a
=
i
)
{
// ...
i
=
0
;
}
In the while-loop, the constructor and destructor are each called twice, once for the condition that succeeds and once for the condition that fails
.
—
end example
]
—
end note
]