🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.modula2
Article #4602

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

#4602
From: Joe English
Date: Sun, 29 Jan 1989 23:43
35 lines
1198 bytes
crew@Polya.Stanford.EDU (Roger Crew) writes:
>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.
>Hint:  the answer is *not*
>
>	char a, b, c;
>	...
>	for (c = a; c <= b; ++c) { ... }
>
>(just try a = 0 and b = 255 in the case of 8 bit chars).


Howzabout

         int a, b, c;
         ...
         for (c = a; c <= b; ++c) { ..., but use "(char)c" instead of "c" }

?

Or
         char a,b,c;
         ...
         for (c = a; ; ++c) { ... if (c == b) break; }


--Joe English

  jeenglis@nunki.usc.edu
Technical Details
Message-ID: <2510@nunki.usc.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!nrl-cmf!ames!ucsd!orion.cf.uci.edu!oberon!nunki.usc.edu!jeenglis
References: <19579@agate.BERKELEY.EDU> <8515@lanl.gov> <6419@polya.Stanford.EDU>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!nrl-cmf!ames!ucsd!orion.cf.uci.edu!oberon!nunki.usc.edu!jeenglis
From: jeenglis@nunki.usc.edu (Joe English)
Newsgroups: comp.lang.modula2
Subject: Re: "for" loops (was Re: C++ vs. Modula2)
Message-ID: <2510@nunki.usc.edu>
Date: 29 Jan 89 23:43:09 GMT
References: <19579@agate.BERKELEY.EDU> <8515@lanl.gov> <6419@polya.Stanford.EDU>
Reply-To: jeenglis@nunki.usc.edu (Joe English)
Distribution: na
Organization: University of Southern California, Los Angeles, CA
Lines: 35