Xref: utzoo comp.lang.modula2:1247 comp.lang.c:15918 Path: utzoo!utgpu!watmath!clyde!ima!cfisun!lakart!dg From: dg@lakart.UUCP (David Goodenough) Newsgroups: comp.lang.modula2,comp.lang.c Subject: Re: "for" loops (was Re: C++ vs. Modula2) Message-ID: <405@lakart.UUCP> Date: 30 Jan 89 16:28:15 GMT References: <1611@csuna.UUCP> Organization: Lakart Corporation, Newton, MA Lines: 48 From article <1611@csuna.UUCP>, by abcscagz@csuna.UUCP (stepanek/cs assoc): > Actually, C's "for" can be duplicated EXACTLY by C's "do ... while" loops. > Consider: > > for (i = 0; i <= 17; ++i) > { > stuff(); > more_stuff(); > } > > versus: > > i = 0; > do { > stuff(); > more_stuff(); > } while (++i <= 17); Yes, but how about: for (i = 0; i <= a; i++) { lots_of_stuff(); } against: i = 0; do { lots_of_stuff(); } while (++i <= a); when the value of a is (say) -5. Are you _SURE_ these two are the same? Better would be to say a for loop can be replaced by a while loop: i = 0; while (i <= a /* or 17 */) { lots_of_stuff(); i++; } -- dg@lakart.UUCP - David Goodenough +---+ IHS | +-+-+ ....... !harvard!xait!lakart!dg +-+-+ | AKA: dg%lakart.uucp@xait.xerox.com +---+