home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / programm / 3100 < prev    next >
Encoding:
Text File  |  1992-11-10  |  1.6 KB  |  48 lines

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