Article View: comp.std.c
Article #3371Re: How to eliminate GOTO?
From: halasz
Date: Thu, 24 Aug 1995 01:47
Date: Thu, 24 Aug 1995 01:47
41 lines
2072 bytes
2072 bytes
On 2 Aug 1995, Gang Zhang wrote
: Suppose you have the following:
: for(i=0;i<10;i++)
: for(j=0;j<10;j++){
: /* some other code here to set condition */
: if(condition)goto Done;
: }
:
: Done:
dmi@byron.apana.org.au (DMI) writes
:Just replace the "goto Done;" with "break;"
In article <41cke4$gtd@sparcserver.lrz-muenchen.de>, ua302aa@sun2.lrz-muenchen.de (Kurt Watzka) writes
: Which will change the semantics of the piece of code, but yes, the
: string "goto" will no longer be visible to the reader. Gang Zhang
: wants to break out of two nested loops, and break breaks out of
: exactly one control construct.
:
: Replacing "goto", as used in the above example, with "break" does
: not improve the structure of your program. The conditional jump
: will still be there, and all you have done is add some syntactic
: shugar to it.
If break were alloud to break out of both loops, it would be a most useful
bit of sugar indeed. For the problem with "goto" is its structure-breaking;
the use of "break" assures that control gos to the end of a syntactic
construct: the end of enclozind loop (or *sigh* "switch", but therefore a
from-deeper ending "break" is even more needed). If this were alloud,
much would be gaind:
iLoop: for(i=0;i<10;i++)
for(j=0;j<10;j++){
/* some other code here to set condition */
if(condition) break iLoop;
}
It would be even better if this label were syntacticlie separat from
that which "goto" can pass control to. If this were the first C, I
would require a kieword, "label", for "goto", and uze the colon for
"break" and "continue".
Technical Details
Message-ID:
<41glno$3a0@caip.rutgers.edu>Path:
arc1-ca.pugleaf.net!caip.rutgers.edu!not-for-mailReferences:
<3vn1ht$kj8@martha.utk.edu> <41cke4$gtd@sparcserver.lrz-muenchen.de>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!caip.rutgers.edu!not-for-mail From: halasz@caip.rutgers.edu Newsgroups: comp.std.c,comp.lang.c Subject: Re: How to eliminate GOTO? Date: 23 Aug 1995 21:47:36 -0400 Organization: Rutgers University Message-ID: <41glno$3a0@caip.rutgers.edu> References: <3vn1ht$kj8@martha.utk.edu> <41cke4$gtd@sparcserver.lrz-muenchen.de> NNTP-Posting-Host: caip.rutgers.edu