🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: use of the break statement

#2240
From: Jonas J. Schlein
Date: Mon, 11 Mar 1996 01:29
44 lines
1365 bytes
<news@chaos.kulnet.kuleuven.ac.be> wrote:
|> I like to code loops in the following way:
|> 
|>     for (;;)
|>     {
|>          if (condition)
|>          {
|>               // do something

Of course you would actually use /* */ style comments in actual C
code which is intended to be ANSI C complaint?

|>          }
|>          else break;
|>     }
|> 
|> Works fine for me: the loop has one exit point and there are no 
|> superfluous "OK"-variables to track.
|> 
|> For instance, when you scan a textfile:
|> 
|>     for (;;)
|>     {
|>         fgets (,, f);
|>         if (! feof (f))
|>         {
|>              ...
|>         }

Why not:

if (fgets (,, f) == NULL)
{
...
}

Then you don't need to use the feof() function at all.

|>         else break;
|>     }
-- 
"If it wasn't for C, we would be using BASI, PASAL, and OBOL."

Jonas J. Schlein  (schlein@gl.umbc.edu)
Technical Details
Message-ID: <4hvvlq$ope@solutions.solon.com>
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
References: <4h4dp2$8ml@solutions.solon.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
From: schlein@umbc.edu (Jonas J. Schlein)
Newsgroups: comp.lang.c.moderated
Subject: Re: use of the break statement
Date: 10 Mar 1996 19:29:30 -0600
Organization: University of Maryland Baltimore County
Sender: clc@solutions.solon.com
Approved: clc@solutions.solon.com
Message-ID: <4hvvlq$ope@solutions.solon.com>
References: <4h4dp2$8ml@solutions.solon.com>
NNTP-Posting-Host: solutions.solon.com