🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: use of the break statement

#2143
From: Network News
Date: Fri, 01 Mar 1996 16:05
44 lines
2198 bytes
Bill Winn <bill_winn@acm.org> 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.
>
>I beg to differ.  break, used in the context of loops, is nothing more than 
>a glorified goto statement.

True, and it's a very useful type of goto.  I don't see how this is
relevant to what I wrote.

>                             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?

Because it's neater to use break.

>break is *never* the only way that a loop can stop executing.

Not true.  Counterexample:

while(1) { if(foo()) break; }

This loop won't terminate except by execution of the break statement.
(longjmp()ing out of foo() doesn't count.)  The loop could be rewritten
not to use break:

while(!foo());

but the loop as I wrote it first will only terminate via break.  That's
what I meant by "I sometimes have a break being the /only/ way to exit
a loop".  (Of course, when I do it it's more justifiable than it is in
this trivial case.)

Can we please avoid this thread becoming a flamewar on goto?  It
started as a discussion of an unusual feature of a coding standard.

-zefram
-- 
Andrew Main <zefram@dcs.warwick.ac.uk>
Technical Details
Message-ID: <4h7787$5do@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: Network News <news@dcs.warwick.ac.uk>
Newsgroups: comp.lang.c.moderated
Subject: Re: use of the break statement
Date: 1 Mar 1996 10:05:27 -0600
Organization: Department of Computer Science, Warwick University, England
Sender: clc@solutions.solon.com
Approved: clc@solutions.solon.com
Message-ID: <4h7787$5do@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-Nntp-Posting-Host: stone
X-Stardate: [-31]7133.24
X-Us-Congress: Moronic fuckers