From -4078341154722711976
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/21
Message-ID: <01bbbd45$c3251100$0a2920cc@landspeeder.delta.com>#1/1
X-Deja-AN: 191114126
references: <01bbb541$57db1d60$31d8cac6@chico> <53f2vu$fd0@panix.com> <m3hgo3ns0p.fsf@gabi-soft.fr> <325D288D.3713@ebc.ericsson.se> <01bbb6f8$a1740320$31d8cac6@chico> <01bbbaee$5dafb680$0a2920cc@landspeeder.delta.com> <01bbbbee$2e7bdaa0$1d76adce@azguard>
x-original-date: Fri, 18 Oct 1996 23:34:59 GMT
organization: -
x-auth: PGPMoose V1.1 PGP comp.std.c++
newsgroups: comp.std.c++
originator: austern@isolde.mti.sgi.com


> I've seen your idea of 'super break' or 'super continue' and
relative-level
> continues/breaks in this thread before. The 'iterate' statement for
looping
> without test sounds novel, but it seems a bit unsafe. (Does an 'iterate'
> statement also skip the 'next' clause in for loops? Overall, it sounds
like
> a good way to start an I/O hang or a fork bomb.)

It would jump past the test and next clauses in a typical for loop. Other
kinds of loops aren't that complicated.

You know how for loops are typically compiled right?

for (init;test;next) { block; }

compiles to the equivalent while-statement with goto:

init;
goto pastnext
while (test) {
  next;
  pastnext:
  block;
  beforetest:
}

The iterate statement would branch to pastnext.
The continue statement would instead branch to beforetest.

The iterate statement would always continue the loop. The continue
statement may cause exiting of the loop.

I've found it mostly useful in loops where you're modifying the control
variable inside the loop.  It would also enable a kind of open-bottomed do:

do { 
  if (x) iterate;
  if (y) iterate;
  if (z) iterate;
} while (false);
 
> My main problem with relative-level breaks is the maintenance headache
that
> would ensue. Breaking out of N levels makes it much harder to analyze the
> looping behavior for nested loops or when adding a new layer of nesting.
> C++ maintenance is hard enough already; try hunting down which overloaded
> operator gets called in a given context, especially when namespaces are
> involved. At least with 'labeled' breaks/continues it's easier to spot
> where the control transfers to. To make it really easy, you could even
put
> the label at the *end* of the loop. Oh... wait... that's exactly what
goto
> does now.

Problem with goto happens when you have to start hunting through a large
function for the target label to see where it goes. With relative breaks
you know implicitly where it's going.  Perhaps actually it would be better
to label the STATEMENT, then break on that label, which would exit the loop
which was so labeled, or continue the loop with the label, etc..  I think
that's what the other guy suggested.

In my language it was a more structured alternative to the goto statement,
which isn't included.
 
> I don't think maintenance problems get enough attention in C++. It's
still
> a young enough language--one that's only slowly been accepted in many
> places--that more programs are still in the 'building' phase than in the
> 'maintaining' phase. Spend some time reading other people's C++ in the
late
> integration or maintenance phases of a project, and you'll see what I
mean.
> The language solves a lot of C's scalability problems, but introduces
> several of its own. In particular, I know why the Java people outlawed
> operator overloading.

Operator overloading is one of the reasons my code is actually readable.
Would look like crap if it was all function calls.  But I see your point.
---
[ 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 
]



