Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84; site rlgvax.UUCP
Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!godot!harvard!seismo!rlgvax!guy
From: guy@rlgvax.UUCP (Guy Harris)
Newsgroups: net.lang.c
Subject: Re: "break " vs. "goto "
Message-ID: <345@rlgvax.UUCP>
Date: Sat, 12-Jan-85 01:49:15 EST
Article-I.D.: rlgvax.345
Posted: Sat Jan 12 01:49:15 1985
Date-Received: Sun, 13-Jan-85 09:20:20 EST
References: <7198@brl-tgr.ARPA>
Organization: CCI Office Systems Group, Reston, VA
Lines: 47
> By this reasoning we can quickly reduce ourselves to working with a turing
> machine. A while statement is redundant because we have goto and if
> statements. "break " reflects a structured concept that mirrors how I
> view a problem being solved; besides it is not as random and clumsy as a goto.
The difference is that writing a "while" loop using "if" and "goto" yields
clumsy and harder-to-read code; replacing the word "break" with the word
"goto" merely makes the program "goto"-less. A "break" (or a "continue") is
a fairly arbitrary transfer of control; "goto" is, admittedly, more arbitrary,
but all of them require you to read a bit to discover where control is
actually going.
for () {
.
.
.
break foobar;
}
}
foobar:
is no less clumsy than
for () {
.
.
.
goto foobar;
}
}
foobar:
The only possible merit of labelled "break" and "continue" is that they
can't be misused in the ways that "goto" can. There are many ways of
writing poor code, and since we can't make "goto" go away in C we're stuck
with that particular way. We'll have to rely on education to prevent
spaghetti code. (There are instances where using "goto"s to cause two
separate paths through code to join at common code is *more* readable, say,
than duplicating the code. Admittedly, in the one recent instance I've
written of this sort, the whole thing should be done using a different
technique of joining those paths, but that's competing with several other
items on my TODO list.)
Guy Harris
{seismo,ihnp4,allegra}!rlgvax!guy