🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: use of the break statement

#2114
From: news
Date: Thu, 29 Feb 1996 14:38
34 lines
1197 bytes
news:4gj0jm$lm8@solutions.solon.com
mjs@hubcap.clemson.edu (M. J. Saltzman) wrote:

>See the other thread running now on using goto.  A break in a loop is
>effectively a goto out of (one level of) the loop, so any loop
>containing a break contains multiple exits.  The disadvantages of
>multiple exits are:
> (text deleted)

I like to code loops in the following way:

    for (;;)
    {
         if (condition)
         {
              // do something
         }
         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))
        {
             ...
        }
        else break;
    }
Technical Details
Message-ID: <4h4dp2$8ml@solutions.solon.com>
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
From: news@chaos.kulnet.kuleuven.ac.be
Newsgroups: comp.lang.c.moderated
Subject: Re: use of the break statement
Date: 29 Feb 1996 08:38:26 -0600
Organization: KUL
Sender: clc@solutions.solon.com
Approved: clc@solutions.solon.com
Message-ID: <4h4dp2$8ml@solutions.solon.com>
NNTP-Posting-Host: solutions.solon.com
X-Mailer: Mozilla 1.2N (Windows; I; 16bit)