8 Statements [stmt.stmt]

8.6 Iteration statements [stmt.iter]

8.6.1 The while statement [stmt.while]

In the while statement the substatement is executed repeatedly until the value of the condition ([stmt.select]) becomes false.
The test takes place before each execution of the substatement.
When the condition of a while statement is a declaration, the scope of the variable that is declared extends from its point of declaration ([basic.scope.pdecl]) to the end of the while statement.
A while statement is equivalent to
label :
{
	if ( condition ) {
		statement
		goto label ;
	}
}
Note
: The variable created in the condition is destroyed and created with each iteration of the loop.
Example
:
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
 ]