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