Another "D" idea (Oh no, not again!)

Brian Campbell brianc at cognos.uucp
Tue Mar 29 02:48:28 AEST 1988


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.

I brought this one up some time ago.  I think the response was the
usual "lack of prior art."  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.

I think the syntax is interesting.  It resembles a label "in reverse"
and in fact tells the compiler to insert a label at the end of the
current statement block.  I don't know where braces should go though...
-- 
Brian Campbell        uucp: decvax!utzoo!dciem!nrcaer!cognos!brianc
Cognos Incorporated   mail: POB 9707, 3755 Riverside Drive, Ottawa, K1G 3Z4
(613) 738-1440        fido: (613) 731-2945 300/1200, sysop at 1:163/8



More information about the Comp.lang.c mailing list