Another "D" idea (Oh no, not ag

mcdonald at uxe.cso.uiuc.edu mcdonald at uxe.cso.uiuc.edu
Mon Mar 21 00:22:00 AEST 1988



>	... suggesting a break n construct to escape n levels up.

>Some languages have this.  It doesn't really work very well.  The
>problem is that it is a maintenance nightmare.  If you have deeply
>nested code (and that is where this thing would be used) and you
>change an intermediate level of nesting you also have to change all
>of those lower level 'break n's.  Moreover it can be, shall we say,
>obscure as to where that 'break 5' is returning control to.

>I am inclined to believe that labelled escapes are somewhat better.
>We have already gone over this one, and several people with large
>clubs have convinced me that it is not worth bothering with.

>The situation boils down to this:  There is no good way in block
>structure code to deal with multi-level escapes.  It appears to be
>a fundamental property of block structured code.

>There is only one real cure:  Don't write deeply nested code that
>needs multi-level escapes.

C has a construct just exactly for this situation. It is easy to use,
portable, and very easy to maintain, because it doesn't depend
on the way loops nest:

while ( ick) {
    for (i = 2633; i < 7399; i += 23 ){
        do {
            while(foo()   ) {
                 ...
                 if(We_finished_early) goto all_the_way_out;
            }
        } while(mm < -11 );
     }
 }

all_the_way_out:
       ...

Doug McDonald



More information about the Comp.lang.c mailing list