digitalmars.D - enhance do...while scope
- Kramer (17/17) Jun 03 2005 I know this has been suggested before, but I think it would be really ni...
- Tom S (4/14) Jun 03 2005 --
- Trevor Parscal (8/28) Jun 03 2005 easy to read, and consistent with other loops. :)
- clayasaurus (9/34) Jun 03 2005 What about this potential situation...
- Trevor Parscal (19/61) Jun 03 2005 it should act no different than
- Brad Beveridge (12/54) Jun 03 2005 The same thing should happen as if this happened
- Kramer (7/41) Jun 03 2005 I believe it should, but the variable in the while(...) should be scoped...
- Trevor Parscal (7/12) Jun 03 2005 Always so long as I have been programming.
- Regan Heath (13/43) Jun 03 2005 Good point. Good replies. Assuming the change is made, and behaviour
I know this has been suggested before, but I think it would be really nice if the while() at the end of a do...while loop could have visibilty to variables in the loop. It's a minor thing and it doesn't hinder coding, but I think this: is nicer than: I think it just brings the code closer to what the programmer intended. I think that's one of D's goals, no? -Kramer
Jun 03 2005
/me suggested it as well... It still gets my vote... Walter ? :) Kramer wrote:I know this has been suggested before, but I think it would be really nice if the while() at the end of a do...while loop could have visibilty to variables in the loop. (...)-- Tomasz Stachowiak /+ a.k.a. h3r3tic +/
Jun 03 2005
Tom S wrote:/me suggested it as well... It still gets my vote... Walter ? :) Kramer wrote:easy to read, and consistent with other loops. :) Trevor Parscal votes YES! -- Thanks, Trevor Parscal www.trevorparscal.com trevorparscal hotmail.comI know this has been suggested before, but I think it would be really nice if the while() at the end of a do...while loop could have visibilty to variables in the loop. (...)
Jun 03 2005
Kramer wrote:I know this has been suggested before, but I think it would be really nice if the while() at the end of a do...while loop could have visibilty to variables in the loop. It's a minor thing and it doesn't hinder coding, but I think this: is nicer than: I think it just brings the code closer to what the programmer intended. I think that's one of D's goals, no? -KramerWhat about this potential situation... char[] input; do { char[] input = readLine(); } while (input) Should the compiler not compile this?
Jun 03 2005
clayasaurus wrote:Kramer wrote:it should act no different than int i = 50; for(int i = 0; i < 3; i++) { writefln(itoa(i)); } /// output 0 1 2 /// I don't think this will break any code. The scope of the (condition) in the while should just be the same scope as between the { .. } of the do. -- Thanks, Trevor Parscal www.trevorparscal.com trevorparscal hotmail.comI know this has been suggested before, but I think it would be really nice if the while() at the end of a do...while loop could have visibilty to variables in the loop. It's a minor thing and it doesn't hinder coding, but I think this: is nicer than: I think it just brings the code closer to what the programmer intended. I think that's one of D's goals, no? -KramerWhat about this potential situation... char[] input; do { char[] input = readLine(); } while (input) Should the compiler not compile this?
Jun 03 2005
clayasaurus wrote:Kramer wrote:The same thing should happen as if this happened { int x; while(1) { int x; x = 1; // inner-most scope x is used } } At least, that makes the most sense to me. BradI know this has been suggested before, but I think it would be really nice if the while() at the end of a do...while loop could have visibilty to variables in the loop. It's a minor thing and it doesn't hinder coding, but I think this: is nicer than: I think it just brings the code closer to what the programmer intended. I think that's one of D's goals, no? -KramerWhat about this potential situation... char[] input; do { char[] input = readLine(); } while (input) Should the compiler not compile this?
Jun 03 2005
I believe it should, but the variable in the while(...) should be scoped to the lexically enclosing braces. So, in the case that there was no /input/ variable in the while(...), the compiler would find the definition outside of the do...while. Isn't that how other scoping issues are handled - can't find it in the most enclosing scope, go up? -Kramer In article <d7qgb1$1bfb$1 digitaldaemon.com>, clayasaurus says...Kramer wrote:I know this has been suggested before, but I think it would be really nice if the while() at the end of a do...while loop could have visibilty to variables in the loop. It's a minor thing and it doesn't hinder coding, but I think this: is nicer than: I think it just brings the code closer to what the programmer intended. I think that's one of D's goals, no? -KramerWhat about this potential situation... char[] input; do { char[] input = readLine(); } while (input) Should the compiler not compile this?
Jun 03 2005
Kramer wrote:I believe it should, but the variable in the while(...) should be scoped to the lexically enclosing braces. So, in the case that there was no /input/ variable in the while(...), the compiler would find the definition outside of the do...while. Isn't that how other scoping issues are handled - can't find it in the most enclosing scope, go up?Always so long as I have been programming. -- Thanks, Trevor Parscal www.trevorparscal.com trevorparscal hotmail.com
Jun 03 2005
On Fri, 03 Jun 2005 16:59:30 -0400, clayasaurus <clayasaurus gmail.com> wrote:Kramer wrote:Good point. Good replies. Assuming the change is made, and behaviour updated as suggested in the replies... I'd just like to add that this request changes the behaviour of do/while such that it no longer behaves like it does in C/C++ (and Java?). So, when porting code, copying a do/while loop to D could (in cases like the above) cause different behaviour to the original intent. So, while I like this idea, and think the 3 replies/answers are the "way to go"(tm) I wanted to note that it will break consistency with C/C++ (and maybe Java) and for those reasons Walter might not go for it, we'll just have to see. ReganI know this has been suggested before, but I think it would be really nice if the while() at the end of a do...while loop could have visibilty to variables in the loop. It's a minor thing and it doesn't hinder coding, but I think this: is nicer than: I think it just brings the code closer to what the programmer intended. I think that's one of D's goals, no? -KramerWhat about this potential situation... char[] input; do { char[] input = readLine(); } while (input) Should the compiler not compile this?
Jun 03 2005