Article View: comp.lang.modula2
Article #4615Re: "for" loops (was Re: C++ vs. Modula2)
From: David Goodenough
Date: Mon, 30 Jan 1989 16:28
Date: Mon, 30 Jan 1989 16:28
48 lines
1279 bytes
1279 bytes
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 +---+
Technical Details
Message-ID:
<405@lakart.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!watmath!clyde!ima!cfisun!lakart!dgReferences:
<1611@csuna.UUCP>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,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