Another "D" idea (Oh no, not again!)
Ray Butterworth
rbutterworth at watmath.waterloo.edu
Wed Mar 30 00:54:00 AEST 1988
In article <2571 at cognos.UUCP>, brianc at cognos.uucp (Brian Campbell) writes:
> In article <316 at wsccs.UUCP> val at wsccs.UUCP (Val Kartchner) writes:
> > I also think that there should be something like "break 'n';" (Where
> > 'n' is a constant integer. Variables would be interesting and floats
> > highly ambiguous.) I've often been deep in multiple loops, and wanted
> > to get out a few levels.
> My suggestion was to add labels to looping constructs:
> while (...) :top
> while (...)
> break :top;
> if (...)
> continue :top;
> The label is far less confusing and requires less maintenance than
> specifying the number of levels to exit. It should also make the
> compiler's job easier since it is specifically told that interior
> statement blocks may be exited abnormally.
But that is not really any clearer than what is already available
in the language:
for ( ; 0 != (file=fopen(...)); fclose(file)) samefile: {
while (0 != (line = fgetl(...))) sameline: {
for (index=0; 0 != (c=line[index]); ++index) samechar: {
...
if (blah()) goto nextfile;
blahblah();
if (blahblahblah()) goto sameline;
...
nextchar:;
}
nextline:;
}
nextfile:;
}
And I don't feel the slightest guilt in using "goto" in this way.
More information about the Comp.lang.c
mailing list