The following syntax is valid:
while (int i = get_data())
{
}
But the following is not:
do
{
} while (int i = get_data());
It would be very unnatural to have a declaration of i
after the block and to then be able to access it in the block. Declaration in for
and while
are nice short-hands that give limited-scope use to a variable that is needed in the loop logic.
Cleaner to do it this way:
int i;
do {
i = get_data();
// whatever you want to do with i;
} while (i != 0);