🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #6758

Breaking loops (Re: Anyone want to design a language?)

#6758
From: Felix Lee
Date: Tue, 20 Feb 1990 15:48
25 lines
1465 bytes
Scott MacHaffie <machaffi@cs.washington.edu> wrote:
>Unconditional loops have a serious problem: you have to read all of the
>code inside the loop to find out when (or if) it terminates.

Well, not if you undent the terminating conditions properly:
	loop
	    do_stuff();
	break cleanup() when (done);
	    do_more_stuff();
	end loop;

Unfortunately this isn't convenient in most languages.  C doesn't have
an inverted if statement, so undenting is confusing:
	for (;;) {
	    do_stuff();
	if (done) { cleanup(); break; }
	    do_more_stuff();
	}
The last brace looks like it closes the if statement.  I usually just
mark break statements with a /*BREAK*/ off to the right somewhere.

Ada has "EXIT loop WHEN condition;" which you can undent, but doesn't
provide for a cleanup clause.  But you often don't need one anyway.
--
Felix Lee	flee@shire.cs.psu.edu	*!psuvax1!flee
Technical Details
Message-ID: <E62*ob@cs.psu.edu>
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!samsung!brutus.cs.uiuc.edu!psuvax1!news
References: <22569:05:10:24@stealth.acf.nyu.edu> <8475@wpi.wpi.edu> <4489:05:14:19@stealth.acf.nyu.edu> <10790@june.cs.washington.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!samsung!brutus.cs.uiuc.edu!psuvax1!news
From: flee@shire.cs.psu.edu (Felix Lee)
Newsgroups: comp.lang.misc
Subject: Breaking loops (Re: Anyone want to design a language?)
Message-ID: <E62*ob@cs.psu.edu>
Date: 20 Feb 90 15:48:51 GMT
References: <22569:05:10:24@stealth.acf.nyu.edu> <8475@wpi.wpi.edu>
 <4489:05:14:19@stealth.acf.nyu.edu> <10790@june.cs.washington.edu>
Sender: news@cs.psu.edu (Usenet)
Distribution: usa
Organization: Penn State University Computer Science
Lines: 25