Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
January 07, 2004 scope of variables in do-while | ||||
---|---|---|---|---|
| ||||
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. |
January 07, 2004 Re: scope of variables in do-while | ||||
---|---|---|---|---|
| ||||
Posted in reply to Robert | 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'));
|
January 07, 2004 Re: scope of variables in do-while | ||||
---|---|---|---|---|
| ||||
Posted in reply to Robert | 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. > |
January 08, 2004 Re: scope of variables in do-while | ||||
---|---|---|---|---|
| ||||
Posted in reply to Robert | 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 :) |
January 08, 2004 Re: scope of variables in do-while | ||||
---|---|---|---|---|
| ||||
Posted in reply to Robert | 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.
|
January 11, 2004 Re: scope of variables in do-while | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ilya Minkov | 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')); |
January 11, 2004 Re: scope of variables in do-while | ||||
---|---|---|---|---|
| ||||
Posted in reply to Heretic | 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... > > > >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 :) |
Copyright © 1999-2021 by the D Language Foundation