home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / pascal / 7838 < prev    next >
Encoding:
Internet Message Format  |  1993-01-04  |  1.4 KB

  1. Path: sparky!uunet!olivea!charnel!sifon!thunder.mcrcim.mcgill.edu!poly-vlsi!music.mus.polymtl.ca
  2. From: CT80@music.mus.polymtl.ca (Steph)
  3. Newsgroups: comp.lang.pascal
  4. Subject: RE: Why doesn't this cause an error?
  5. Message-ID: <03JAN93.21792946.0032@music.mus.polymtl.ca>
  6. Date: 4 Jan 93 01:10:43 GMT
  7. References: <1993Jan01.220029.27699@crash>
  8. Sender: usenet@music.mus.polymtl.ca
  9. Organization: Ecole Polytechnique de Montreal
  10. Lines: 31
  11.  
  12. In article <1993Jan01.220029.27699@crash> tech@crash.cts.com (Don Bontemps) writes:
  13. >I know there is probably an easy answer to this question, but here is
  14. >a portion of a routine that I am using to convert a lowercase string
  15. >into an uppercase string.
  16. >
  17. >
  18. >    readln(comment);
  19. >    for l := 1 to length of comment do comment[l] := upcase(comment[l]);
  20. >
  21. >
  22. >
  23. >If the user doesn't enter anything, this causes the length of comment to
  24. >become zero and what confuses me is that this event does not cause any
  25. >error whatsoever.  I would figure that "for l := 1 to 0" to cause a
  26. >run-time error or some other type of error, but it doesn't.  Why not??
  27. >
  28. >
  29. >.
  30. >.
  31.  
  32. Someone probably answered this one already, but anyway, here goes..
  33.  
  34. The FOR loop checks the condition before doing the statement.  Since
  35. you have a loop from 1 to 0, well it goes something like this ..
  36.  
  37. for l := 1 to 0 do ..
  38.  
  39. 1st run -> (l := 1) > 0, so it gets out of the loop right away.
  40. Makes sense?
  41.  
  42. Steph.
  43.