Article View: comp.lang.c.moderated
Article #2103Re: use of the break statement
From: Bill Winn
Date: Thu, 29 Feb 1996 00:31
Date: Thu, 29 Feb 1996 00:31
35 lines
2105 bytes
2105 bytes
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. 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. break is *never* the only way that a loop can stop executing. There is *always* one or more conditions attached to the execution of the break, and those conditions may server, just as easily, to set the flag described above. Please, no arguments like "my system has hard real-time constraints and can't afford the extra cycles" or "I have memory constraints and can't afford to set aside room for the flag." If you have these arguments against using the flag, I'll *bet* that there are other areas of your system that need to be optimized. -- Bill Winn Software Engineer - Analysts International Corporation ------------------------------- bill_winn@acm.org My views do not express the views of anyone except my alter-ego.
Technical Details
Message-ID:
<4h2s54$o3@solutions.solon.com>Path:
arc1-ca.pugleaf.net!solon.com!not-for-mailReferences:
<4gfcl7$2ls@solutions.solon.com> <4gnbcp$biq@solutions.solon.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail From: bill_winn@acm.org (Bill Winn) Newsgroups: comp.lang.c.moderated Subject: Re: use of the break statement Date: 28 Feb 1996 18:31:32 -0600 Organization: Delco Electronics Corp. Sender: clc@solutions.solon.com Approved: clc@solutions.solon.com Message-ID: <4h2s54$o3@solutions.solon.com> References: <4gfcl7$2ls@solutions.solon.com> <4gnbcp$biq@solutions.solon.com> NNTP-Posting-Host: solutions.solon.com X-Newsreader: WinVN 0.93.11