goto jumps into loops
guido at boring.UUCP
guido at boring.UUCP
Sun Apr 20 02:29:52 AEST 1986
Dave Harmon obviously doesn't know C and didn't bother to test the C
version of his example: it contains i=MAX instead of i==MAX and
while(in(..)) instead of while(!in(...)) -- the latter no doubt stemming
from a slavish translation of Pascal's until <condition>.
Nevertheless, his problem is not one that's solved better with the use
of goto's. Here's my code (tested -- it didn't need debugging :-).
wrtlist(s) set *s; {
int count= 0; /* Counts elements in range currently being printed */
int e;
for (e= 0; e <= MAX; ++e) {
if (in(e, s)) {
if (count == 0)
printf(" %d", e);
++count;
}
else {
if (count > 1) printf("-%d", e-1);
count= 0;
}
}
}
--
Guido van Rossum, CWI, Amsterdam <guido at mcvax.UUCP>
More information about the Comp.lang.c
mailing list