new do-while syntax

Stuart Gathman stuart at bms-at.UUCP
Thu Dec 22 12:46:03 AEST 1988


In article <8562 at alice.UUCP>, ark at alice.UUCP (Andrew Koenig) writes:

> 	int i, status, count = 0;
> 	char temp[THINGSIZE];
> 	do {
> 		readthing(precious);
> 		++count;
> 		for (i = 0; i < THINGSIZE; i++)
> 			temp[i] = precious[i];
> 		status = munge(temp);
> 	} while (status) {
> 		for (i = 0; i < THINGSIZE; i++) {
> 			if (temp[i] != precious[i])
> 				printf ("munge changed element %d of line %d\n",
> 					i, count);
> 		}
> 	}

This is a necessary contruct.  In a structured assembler language I developed,
it goes like this:

	LOOP				REPEAT
		statements			statements
	WHILE	WHEN		or	UNTIL	WHEN
		statements			statements
	THEN 	cond			THEN	cond
	

The WHILE part was executed first.  *Any* condition could contain
a 'WHEN' clause.  (As in 'IF (A,LT,B),OR,WHEN . . .')

A generalized WHEN construct would be welcome in 'C'.  The specific
case being discussed, however, is handled quite well
by the break statement in standard 'C'!

	for (;;) {
	  c = getchar();
	  if (c == EOF) break;
	  process(c);
	}
-- 
Stuart D. Gathman	<stuart at bms-at.uucp>
			<..!{vrdxhq|daitc}!bms-at!stuart>



More information about the Comp.lang.c mailing list