Article View: comp.std.c
Article #3461Re: Multi-level break and elimination of GOTO
From: Fredrik Bredberg
Date: Mon, 06 Nov 1995 11:15
Date: Mon, 06 Nov 1995 11:15
71 lines
3741 bytes
3741 bytes
Andrew Dunbar (andrewd@agnus.livewire.com.au) wrote:
:
: Has anyone thought of the possibility of 'named' loops?
:
: for outer (x = 0; x < MAXX; x++)
: {
: for inner (y = 0; y < MAXY; y++)
: {
: if (map[y][x] == '*')
: break (outer);
: }
: }
In article <DHJBHK.ILu@kroete2.freinet.de> erik@kroete2.freinet.de (Erik Corry) writes:
> Definitely better than break(2) or continue(2), but why not do it the
> same way Java does it:
>
> outer:
> for (x = 0; x < MAXX; x++)
> {
> for (y = 0; y < MAXY; y++)
> {
> if (map[y][x] == '*')
> break outer;
> }
> }
>
> It would be a pity to do it differently to Java unless there's
> a good reason. Of course the question is, what do we gain by this?
> You could trivially do the same with goto. It makes more sense
> for continue, actually, which couldn't be done as well with
> goto. But it is utterly unrealistic to talk about removing
> goto from C9X. Java is in a different situation because it
> doesn't have goto in the first place. One of the benefits of
> an almost clean slate design.
I think that Andrew's `named' loops is the best alternative to this
problem that I'v seen so far! The main reason for this is that the
`label' is so closely coupled to the loop constructor.
I'm not that good at Java but as I understand it `goto' is a reserverd
(but not currently used) keyword. So what happens if goto will become
a legal (and used) keyword? Should it be legal to jump to the `outer:'
label by using a goto from any place in the function? It sure looks
like a valid goto label so why not! Suddenly this is not longer a
"clean slate design" to solve the multi-level break problem.
Needlessly to say; I'm heavily against explicit stated break-levels like:
for (x = 0; x < MAXX; x++) {
for (y = 0; y < MAXY; y++) {
if (map[y][x] == '*')
break 2;
}
}
/* The program will continue here after the `break 2;' statement. */
--
+---------------------------+------------------------------------------------+
| Fredrik Bredberg | |
| E-Mail..: frbr@enea.se | |
| Pager...: + 46 746 457371 | Legally - It's questionable |
| Enea Tel: + 46 8 6385067 | Morally - It's disgusting |
| Enea Fax: + 46 8 6385050 | Personally - I like it! |
| EUA User: konfrbr | |
| EUA Tel: + 46 8 7273638 | |
+---------------------------+------------------------------------------------+
| o a Do bear in mind that the opinions expressed in this mail |
| H-+-- \/#\ are my own and that they don not necessarily represent the |
| / ) |\ opinions of my employer or any of my employer's clients. |
+----------------------------------------------------------------------------+
Technical Details
Message-ID:
<rnbohuqj8p3.fsf@euax7i3c01.eua.ericsson.se>Path:
arc1-ca.pugleaf.net!eua.ericsson.se!usenetReferences:
<43pdut$hoh@galaxy.csc.calpoly.edu> <DF8FE3.97H@news.cern.ch> <47eb7k$ckb@news.mel.aone.net.au> <DHJBHK.ILu@kroete2.freinet.de>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!eua.ericsson.se!usenet From: konfrbr@euax7i3c01.eua.ericsson.se (Fredrik Bredberg) Newsgroups: comp.std.c,comp.lang.c Subject: Re: Multi-level break and elimination of GOTO Date: 06 Nov 1995 12:15:04 +0100 Organization: Ellemtel Telecom Systems Labs, Stockholm, Sweden Sender: konfrbr@euax7i3c01.eua.ericsson.se Message-ID: <rnbohuqj8p3.fsf@euax7i3c01.eua.ericsson.se> References: <43pdut$hoh@galaxy.csc.calpoly.edu> <DF8FE3.97H@news.cern.ch> <47eb7k$ckb@news.mel.aone.net.au> <DHJBHK.ILu@kroete2.freinet.de> NNTP-Posting-Host: euax7i3c01.eua.ericsson.se In-reply-to: erik@kroete2.freinet.de's message of Sat, 4 Nov 1995 19:58:32 GMT X-Newsreader: Gnus v5.0.4