🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.modula2
Article #4616

Re: "for" loops (was Re: C++ vs. Modula2)

#4616
From: David Goodenough
Date: Mon, 30 Jan 1989 16:38
34 lines
1091 bytes
From article <6419@polya.Stanford.EDU>, by crew@Polya.Stanford.EDU (Roger Crew):
> Here's a quiz:
> How would you write the following in C?
> 
> 	VAR a, b, c : Char;
> 	...
> 	FOR c = a TO b DO ... END;
> 
> You can even assume that the body of the loop affects neither a nor b.

Probably like this:

	char a, b, c;

	c = a;
	do
	 {
	    grunt();
	 } while (c++ != b);

or like

	for (c = a; c != b; c++)
	 {
	    grunt();
	 }

depending on whether the FOR DO END loop iterates once or never when b == a.
The basic idea is to test for equality rather than relation.
-- 
	dg@lakart.UUCP - David Goodenough		+---+
						IHS	| +-+-+
	....... !harvard!xait!lakart!dg			+-+-+ |
AKA:	dg%lakart.uucp@xait.xerox.com		  	  +---+
Technical Details
Message-ID: <406@lakart.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watmath!clyde!ima!cfisun!lakart!dg
References: <6419@polya.Stanford.EDU>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watmath!clyde!ima!cfisun!lakart!dg
From: dg@lakart.UUCP (David Goodenough)
Newsgroups: comp.lang.modula2
Subject: Re: "for" loops (was Re: C++ vs. Modula2)
Message-ID: <406@lakart.UUCP>
Date: 30 Jan 89 16:38:04 GMT
References: <6419@polya.Stanford.EDU>
Organization: Lakart Corporation, Newton, MA
Lines: 34