🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c.moderated
Article #2120

Re: use of the break statement

#2120
From: Christopher R Volpe
Date: Fri, 01 Mar 1996 15:30
40 lines
2301 bytes
Bill Winn wrote:
> 
> In article <4gnbcp$biq@solutions.solon.com>, news@dcs.warwick.ac.uk
> composed...
> >In code that I write, and see, every day, break is very commonly used
> >to exit a loop.  In fact, I sometimes have a break being the /only/ way
> >to exit a loop.  (Something like perl's split loop body would be a nice
> >addition to the language.)  I don't consider it to be in any way bad
> >style.
> >
> >What does this standard say about continue and goto?
> >
> 
> I beg to differ.  break, used in the context of loops, is nothing more than
> a glorified goto statement. 

False. Since the the break can only "goto" one specific location, it is
no more a glorified goto than is a loop or switch construct, or even an
if-statement for that matter. The above are all "glorified gotos" in
this sense. What makes them different from goto is the non-arbitrariness
of the destination. 

> If you have conditions that force a loop to
> stop executing why not just have a flag that is set when the loop is to
> terminate?  Sure, you have to go to the top of the loop (in the case of for
> and while) to test for the condition, but I would venture a guess that doing
> such will not cause your system to fail.

This approach requires that everything that follows the setting of this
flag be enclosed in an if-statement that tests this flag. That's a
waste, and it hampers readability, especially if you have to nest this
construct multiple levels. Sure, avoiding "break" is always possible.
That doesn't mean it's sensible.


--

Chris Volpe				Phone: (518) 387-7766 (Dial Comm 8*833
GE Corporate R&D			Fax:   (518) 387-6560
PO Box 8, Schenectady, NY 12301		Email: volpecr@crd.ge.com
Technical Details
Message-ID: <4h757h$4ic@solutions.solon.com>
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
References: <4gfcl7$2ls@solutions.solon.com> <4gnbcp$biq@solutions.solon.com> <4h2s54$o3@solutions.solon.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
From: Christopher R Volpe <volpe@ash.crd.ge.com>
Newsgroups: comp.lang.c.moderated
Subject: Re: use of the break statement
Date: 1 Mar 1996 09:30:57 -0600
Organization: GE Corporate Research & Development, Schenectady, NY
Sender: clc@solutions.solon.com
Approved: clc@solutions.solon.com
Message-ID: <4h757h$4ic@solutions.solon.com>
References: <4gfcl7$2ls@solutions.solon.com> <4gnbcp$biq@solutions.solon.com> <4h2s54$o3@solutions.solon.com>
NNTP-Posting-Host: solutions.solon.com
X-Mailer: Mozilla 2.0 (X11; I; SunOS 5.4 sun4m)