D - scope of variables in do-while
- Robert (11/11) Jan 07 2004 I sometimes want to write as:
- Ilya Minkov (3/6) Jan 07 2004 I vote for it! I just ran over the same in C++ today!
- Sean L. Palmer (4/10) Jan 11 2004 Yes. I often wish for this.
- Tony West (14/14) Jan 07 2004 I've had the same problem and yes, it would be nice for the scope to ext...
- Ilya Minkov (5/11) Jan 07 2004 Such a loop is a nonsense anyway, since it either loops only once, or
- Matthew (8/19) Jan 07 2004 How about
- Heretic (3/7) Jan 07 2004 I also vote ;) for this... i wish it was this way everytime i write a do...
- Sean L. Palmer (12/21) Jan 11 2004 while is somewhat ambiguous anyway. Why not go ahead and add until?
- J Anderson (3/15) Jan 07 2004 I like this idea. It could also apply to the last parameter in a for
I sometimes want to write as: do { int c = getchar(); } while(!(c == EOF || c == '\n')); but condition expression of the 'while' is out of scope of 'c'. So, I must write as: int c; do { c = getchar(); } while(!(c == EOF || c == '\n')); Though, I think the former is better than the latter.
Jan 07 2004
I vote for it! I just ran over the same in C++ today! do scope should extend to while. Robert wrote:do { int c = getchar(); } while(!(c == EOF || c == '\n'));
Jan 07 2004
Yes. I often wish for this. Sean "Ilya Minkov" <minkov cs.tum.edu> wrote in message news:bthssm$2s00$1 digitaldaemon.com...I vote for it! I just ran over the same in C++ today! do scope should extend to while. Robert wrote:do { int c = getchar(); } while(!(c == EOF || c == '\n'));
Jan 11 2004
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
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
How about do with (int c) { c = getchar(); } while(!(c == EOF || c == '\n')); Walter, would that be unambiguously parseable? "Robert" <no spam.ne.jp> wrote in message news:bthsbo$2raj$1 digitaldaemon.com...I sometimes want to write as: do { int c = getchar(); } while(!(c == EOF || c == '\n')); but condition expression of the 'while' is out of scope of 'c'. So, I must write as: int c; do { c = getchar(); } while(!(c == EOF || c == '\n')); Though, I think the former is better than the latter.
Jan 07 2004
In article <bthsbo$2raj$1 digitaldaemon.com>, Robert says...I sometimes want to write as: do { int c = getchar(); } while(!(c == EOF || c == '\n'));I also vote ;) for this... i wish it was this way everytime i write a do-while loop :)
Jan 07 2004
while is somewhat ambiguous anyway. Why not go ahead and add until? { int c=getchar(); } until (c > 32); Or it could also start with do do { } until (false); Just prevents a bit of logical negation, may make some source code a wee bit clearer in intent. Sean "Heretic" <Heretic_member pathlink.com> wrote in message news:bti7kf$bou$1 digitaldaemon.com...In article <bthsbo$2raj$1 digitaldaemon.com>, Robert says...do-whileI sometimes want to write as: do { int c = getchar(); } while(!(c == EOF || c == '\n'));I also vote ;) for this... i wish it was this way everytime i write aloop :)
Jan 11 2004
Robert wrote:I sometimes want to write as: do { int c = getchar(); } while(!(c == EOF || c == '\n')); but condition expression of the 'while' is out of scope of 'c'. So, I must write as: int c; do { c = getchar(); } while(!(c == EOF || c == '\n')); Though, I think the former is better than the latter.I like this idea. It could also apply to the last parameter in a for loop, but that's a bit picky.
Jan 07 2004