From -7500840731848510837
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,6bd75668e589c3cb
X-Google-Attributes: gidf78e5,public
From: sean@delta.com (Sean L. Palmer)
Subject: Re: PROPOSAL: Parameterized return/break/continue for nested loops
Date: 1996/10/16
Message-ID: <01bbbaee$5dafb680$0a2920cc@landspeeder.delta.com>#1/1
X-Deja-AN: 190066956
references: <01bbb541$57db1d60$31d8cac6@chico> <53f2vu$fd0@panix.com> <m3hgo3ns0p.fsf@gabi-soft.fr> <325D288D.3713@ebc.ericsson.se> <01bbb6f8$a1740320$31d8cac6@chico>
x-original-date: Wed, 16 Oct 1996 00:04:15 GMT
organization: -
x-auth: PGPMoose V1.1 PGP comp.std.c++
newsgroups: comp.std.c++
originator: austern@isolde.mti.sgi.com


> HOWEVER, having said all that, I agree that the goto SHOULD be removed,
and
> replaced with (a) structured equivalent(s). That is why I propose
> essentially the naming of compound statements. The compound statement's
> name can be used (including scoping rules) by breaks or continues.

I've designed a language construct that does this. It might be applicable.
The actual keywords would probably get tweaked by the committee and are
unimportant for this discussion.

Introduce new keyword "iterate" which is essentially a continue which
transfers control to a point in the loop which immediately follows the
evaluation of the termination condition. In other words, unconditionally
continue the loop.  

Introduce new keyword "super" which can precede any break or continue or
iterate statement. This super keyword causes the break-statement in
question to apply to the loop which contains the loop in which the break
statement appears. Also a valid modifier for break in switch statements,
which I consider to be an outdated mechanism that's error prone by the way.

example:

{
  int x=rand(12);
  for (int i=0; i<8; ++i) {
    for (int j=0; j<i; ++j) {
      if (j>x)
        super break;  //jumps out of the outer for loop.
      if (j==x && i==x)
        break;        //jumps out of the inner for loop
    }
  }
}

More than one 'super' modifier could be added. An alternative syntax which
I actually think would be better is that break and continue (and iterate)
could be followed by a constant positive integral count which determined
how many levels of loops outward to apply it to, and defaulted to one (the
current loop).  So 'break 1;' would be equivalent to the current 'break;',
and 'break 2;' would be equivalent to the 'super break' construct above.

I agree that it would be a nice addition to the language and would allow
the removal of goto altogether, something I consider a good thing, even
though I'm tempted to use it on occasion to minimize redundant code.. that
would be the only practical application of goto if this extended break
feature were added.
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu 
]



