`if (a = b)' (was Standard indentation?)
    Peter da Silva 
    peter at ficc.uu.net
       
    Sun Dec 18 16:06:55 AEST 1988
    
    
  
In article <3049 at arcturus>, evil at arcturus.UUCP (Wade Guthrie) writes:
> The sound of a programmer trying to read a C program flinging himself
> against a wall.
Is that like the sound of one hand clapping?
> In article <8536 at alice.UUCP>, ark at alice.UUCP (Andrew Koenig) writes:
> > 	do	ch = getchar();
> > 	while (ch != EOF)
> > 		process(ch);
> > or, with braces:
> > 	do {
> > 		ch = getchar();
> > 	} while (ch != EOF) {
> > 		process(ch);
> > 	}
This is a wonderful and clean extension to 'C' that solves the loop problem
once and for all!
> I really do not mean to flame this person, but the above constructions
> are EXCEEDINGLY hard to read.  I much perfer the method which already
> exists:
Only if you're not used to it. have you ever done extensive bourne-shell
or Forth programming, where this construct is a common idiom?
> 	while ( (c=getchar()) != EOF)
> 		process(c);
How about (in K&R indenting style, for consistancy):
	do {
		Ask question.
		Get answer.
		Categorise answer.
	} while(answer != exit) {
		Stuff...
		switch(answer) {
		  ...
		}
		And more stuff...
	}
That is, what about the case where the first part of the loop is too complex
to fit in a while statement. Sure, you could put a break in, but isn't this
clearer? The existing while and do loops become special cases.
-- 
Peter da Silva, Xenix Support, Ferranti International Controls Corporation.
Work: uunet.uu.net!ficc!peter, peter at ficc.uu.net, +1 713 274 5180.
Home: bigtex!texbell!sugar!peter, peter at sugar.uu.net.
    
    
More information about the Comp.lang.c
mailing list