🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #5409

Re: Loops

#5409
From: Peter A. Buhr
Date: Wed, 30 Mar 1988 13:04
47 lines
1962 bytes
In article <2488@bsu-cs.UUCP> dhesi@bsu-cs.UUCP (Rahul Dhesi) writes:
>In article <294@tmsoft.UUCP> mason@tmsoft.UUCP (Dave Mason) writes:
>>...
>Unfortunately, somebody modifying code with such a construct will
>seldom be sure that he has tracked down all the exit points.  The same
>problem exists with goto, exit, break, etc.
>
>A possible solution:
>
>     do (2 exits)
>	...
>	while expr
>	...
>	while expr
>	...
>     done
>
>The assertion "(2 exits)" tells the compiler to flag a syntax error if
>the number of loop exits is not exactly 2.  The default, in the absence
>of this assertion, could be exactly one exit.  Also "(no exits)".

A much easier solution is to outdent the exit conditions, as in:

      do
         ...
      while expr
         ...
      while expr
         ...
      done

It is then possible to scan down the margin of the loop and see very
quickly all the exit points. This is the same mechanism that is used
to locate the else clasue of an if statement, as in:

     if ... then                  if ... then
        ...                          ...
        else            vs.       else
        ....                         ...
     end if                       end if

For a more detailed discussion on this stuff see:

Buhr, P. A.
A Case for Teaching Multi-exit Loops to Beginning Programmers.
SIGPLAN Notices,
vol. 20, no. 11, November 1985, pp. 14-22
Technical Details
Message-ID: <17911@watmath.waterloo.edu>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!lll-winken!lll-tis!ames!pacbell!att-ih!att-cb!clyde!watmath!watmsg!pabuhr
References: <2827@enea.se> <1557@pasteur.Berkeley.Edu> <2773@mmintl.UUCP> <294@tmsoft.UUCP> <2488@bsu-cs.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!lll-winken!lll-tis!ames!pacbell!att-ih!att-cb!clyde!watmath!watmsg!pabuhr
From: pabuhr@watmsg.waterloo.edu (Peter A. Buhr)
Newsgroups: comp.lang.misc
Subject: Re: Loops
Message-ID: <17911@watmath.waterloo.edu>
Date: 30 Mar 88 13:04:30 GMT
References: <2827@enea.se> <1557@pasteur.Berkeley.Edu> <2773@mmintl.UUCP> <294@tmsoft.UUCP> <2488@bsu-cs.UUCP>
Sender: daemon@watmath.waterloo.edu
Reply-To: pabuhr@watmsg.waterloo.edu (Peter A. Buhr)
Organization: U. of Waterloo, Ontario
Lines: 46