Article View: comp.lang.c.moderated
Article #2238Re: use of the break statement
From: Ben Jackson
Date: Mon, 11 Mar 1996 01:29
Date: Mon, 11 Mar 1996 01:29
34 lines
1123 bytes
1123 bytes
In article <4h4dp2$8ml@solutions.solon.com>,
<news@chaos.kulnet.kuleuven.ac.be> wrote:
>
>I like to code loops in the following way:
>
> for (;;)
> {
> if (condition)
> {
> // do something
> }
> else break;
> }
That is exactly:
while (condition)
{
// do something
}
(Not that I'd arrange braces like that or use C++ comments in my C code)
Your example includes a statement before the "if", so it doesn't translate
as easily. However, the idiom for processing all the lines of a file with
fgets would be:
while (fgets(...)) {
// do something
}
--
Ben Jackson
ben@ben.com
http://www.ben.com/~ben/
Technical Details
Message-ID:
<4hvvm2$ops@solutions.solon.com>Path:
arc1-ca.pugleaf.net!solon.com!not-for-mailReferences:
<4h4dp2$8ml@solutions.solon.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail From: bjj@sequent.com (Ben Jackson) Newsgroups: comp.lang.c.moderated Subject: Re: use of the break statement Date: 10 Mar 1996 19:29:38 -0600 Organization: Sequent Computer Systems Inc. Sender: clc@solutions.solon.com Approved: clc@solutions.solon.com Message-ID: <4hvvm2$ops@solutions.solon.com> References: <4h4dp2$8ml@solutions.solon.com> NNTP-Posting-Host: solutions.solon.com