www.digitalmars.com         C & C++   DMDScript  

D - Re: scope of variables in do-while

reply Tony West <Tony_member pathlink.com> writes:
I've had the same problem and yes, it would be nice for the scope to extend to
the while expression.

I would imagine that this is not normally supported because of the possibility
that an identifier may be redefined within an inner block, e.g.

int a;
do
{
int a;
blah...
}while (a == 1);

Which "a" is referenced within the while expression?

Fortunately, since D does not allow multiple definitions, this should not be an
issue.

Tony
Jan 07 2004
parent Ilya Minkov <minkov cs.tum.edu> writes:
Tony West wrote:
 int a;
 do
 {
 int a;
 blah...
 }while (a == 1);

Such a loop is a nonsense anyway, since it either loops only once, or never stops, depending on the value of outermost a. That's most probably not what the average coder wants when he writes that. -eye
Jan 07 2004