The following syntax is valid:
while (int i = get_data())
{
}
But the following is not:
do
{
} while (int i = get_data());
We can see why via the draft standard N4140
section 6.4:
1 [...]
condition: expression attribute-specifier-seqopt decl-specifier-seq declarator = initializer-clause attribute-specifier-seqopt decl-specifier-seq declarator braced-init-list2 The rules for conditions apply both to selection-statements and to the
for
andwhile
statements (6.5). [...]
and section 6.5
1 Iteration statements specify looping.
iteration-statement:while
( condition ) statementdo
statementwhile
( expression ) ;
Instead, you're forced to do something ugly like:
int i = get_data();
do
{
} while ((i = get_data())); // double parentheses sic
What is the rationale for this?