🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #5414

Re: Loops

#5414
From: Frank Adams
Date: Wed, 30 Mar 1988 19:04
57 lines
2163 bytes
In article <294@tmsoft.UUCP> mason@tmsoft.UUCP (Dave Mason) writes:
>In article <2773@mmintl.UUCP> franka@mmintl.UUCP (Frank Adams) writes:
>>The more I program, the more convinced I become that the 'while' loop is a
>>mistake.  It just doesn't match the semantics of too many real loops.
>>...
>>The key points are:
>>(1) Exit from any point in the loop.
>>(2) Multiple exits.
>>(3) Code can be associated with any exit point.

I want to re-emphasize point (3) here.  In a structured program, there
should be a (relatively) simple statement of the state of the computation
when you exit from the loop.  When there are multiple bare exit points, it
is likely that the simplicity of that condition must be sacrificed.  This
leads to things like (in pseudo-code):

	for i = 1 to n;
		...
		while P(i);
		...
	end;

	if i > n	/* Check for normal exit from loop */
		...

or even worse kludges.  (I want to emphasize that this is a practical
objection as well as a theoretical one.)

The examples Dave gives are all missing this facility.

>... The do keyword can be followed by 1 or more 'for' clauses, which are
>stepped in parallel:
>	int a[0..29]
>	...
>	do 
>	   for i in 1..20
>	   for ap in a
>	   ...
>	   while i!=ap
>	   ...
>	od

Add optional exit code for each for and while, and you've got my approval.
E.g.,

	   for i in 1..20 else f(t) rof

>(BTW, Frank's idea already exists in at least Concurrent Euclid, Turing:
>	loop
>		...
>		exit when a<>b
>		...
>	end loop
-- 

Frank Adams                           ihnp4!philabs!pwa-b!mmintl!franka
Ashton-Tate          52 Oakland Ave North         E. Hartford, CT 06108
Technical Details
Message-ID: <2797@mmintl.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!att-cb!att-ih!pacbell!ames!necntc!linus!philabs!pwa-b!mmintl!franka
References: <2827@enea.se> <1557@pasteur.Berkeley.Edu> <2773@mmintl.UUCP> <294@tmsoft.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!att-cb!att-ih!pacbell!ames!necntc!linus!philabs!pwa-b!mmintl!franka
From: franka@mmintl.UUCP (Frank Adams)
Newsgroups: comp.lang.misc
Subject: Re: Loops
Message-ID: <2797@mmintl.UUCP>
Date: 30 Mar 88 19:04:19 GMT
References: <2827@enea.se> <1557@pasteur.Berkeley.Edu> <2773@mmintl.UUCP> <294@tmsoft.UUCP>
Reply-To: franka@mmintl.UUCP (Frank Adams)
Organization: Ashton-Tate Corporation, East Hartford Development Center
Lines: 57