home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.programming
- Path: sparky!uunet!mcsun!sunic!dkuug!imada!ravn
- From: ravn@imada.ou.dk (Thorbjoern Ravn Andersen)
- Subject: Re: Help - What Is Wrong?
- Message-ID: <1992Nov10.224330.5513@imada.ou.dk>
- Sender: news@imada.ou.dk (USENET News System)
- Organization: Dept. of Math. & Computer Science, Odense University, Denmark
- References: <536@ulogic.UUCP> <544@ulogic.UUCP> <1992Nov9.154402.16285@hubcap.clemson.edu> <1992Nov10.135848.3730@jyu.fi>
- Distribution: comp
- Date: Tue, 10 Nov 1992 22:43:30 GMT
- Lines: 35
-
- >>Discussing a fragment of code of the form
- >>
- >> for ( i = 0; i != 5; i++ )
- >> ...
- >>
- >>>I've always seen (and used) the "i<max" form of the for loop, and
- >>>messed up when faced w/ anything else. "i!=max" WILL work, but
- >>>is less safe for a number of reasons (more so if initial condition
- >> ^^^^^^^^^
- >>>is set by variable instead of literal).
- >>
-
- [Lotta stuff deleted regarding infinite loops]
-
- Some languages does not use integer variables (prime example is the
- Comal80 I was taught to program in), but reals.
-
- Some times the inaccuracy in the real number operation would cause the
- above test to fail utterly, as 4.999999999999 isn't the same as 5.
- Correct code, but infinite loop.
-
- Our teacher urged us to use the "i<5" instead of "i!=5" in order to
- avoid these pitfalls. Try explaining the inabillity of a computer to
- count to school kids......
-
- (And, no -- I do not use Comal80 anymore. Functional programming is
- much better; much more interesting pitfalls)
-
-
-
- --
- Thorbj{\o}rn Andersen | b="a=\"b=\"++show b++';':b";a="b="++show b++';':b
- ravn@imada.ou.dk | Graph Theory: Building trees out of bridges.
-
-
-