In Why can't you declare a variable inside a do while loop? the OP asks why a declaration in the while-condition of a do-while loop isn't in scope in the do-statement. That would be very unnatural as C/C++ generally follow a "declaration-at-top-of-scope" pattern. But what about the converse - why not extend the scope of any declaration in the do-statement to the while-condition. That would allow
int i;
do {
i = get_data();
// whatever you want to do with i;
} while (i != 0);
to be shortened to
do {
int i = get_data();
// whatever you want to do with i;
} while (i != 0);
which gives a tidy syntax for limiting the scope of the control variable. (Note: I'm aware that this isn't valid syntax - that's the point of the question, why not extend the language to allow this syntax.)
As I note in a comment below, this extension would not break existing code, and would be very much in then spirit of the introduction of for-init (and while-init) scoping.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…