Path: 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 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