[stmt.while] (original) (raw)
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_]