do-while loops
bearophile
bearophileHUGS at lycos.com
Wed Dec 28 05:29:48 PST 2011
One thing that I often find not handy in the design of do-while loops: the scope of their body ends before the "while":
void main() {
do {
int x = 5;
} while (x != 5); // Error: undefined identifier x
}
So I can't define inside them variables that I test in the while().
This keeps the scope clean, but it's not nice looking:
void main() {
{
int x;
do {
x = 5;
} while (x != 5);
}
}
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list