home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / pascal / 7807 < prev    next >
Encoding:
Text File  |  1993-01-02  |  1.6 KB  |  47 lines

  1. Newsgroups: comp.lang.pascal
  2. Path: sparky!uunet!usc!cs.utexas.edu!torn!news.ccs.queensu.ca!slip202.telnet1.QueensU.CA!dmurdoch
  3. From: dmurdoch@mast.queensu.ca (Duncan Murdoch)
  4. Subject: Re: Why doesn't this cause an error?
  5. Message-ID: <dmurdoch.277.726007849@mast.queensu.ca>
  6. Lines: 35
  7. Sender: news@knot.ccs.queensu.ca (Netnews control)
  8. Organization: Queen's University
  9. References: <34851@adm.brl.mil>
  10. Date: Sat, 2 Jan 1993 20:50:50 GMT
  11.  
  12. In article <34851@adm.brl.mil> stone@hilbert.math.grin.edu (John David Stone) writes:
  13. >        Because the Pascal standard specifies that
  14. >
  15. >                for v := e1 to e2 do body
  16. >
  17. >shall be equivalent to
  18. >
  19. >                begin
  20. >                    temp1 := e1;
  21. >                    temp2 := e2;
  22. >                    if temp1 <= temp2 then begin
  23. >                        v := temp1;
  24. >                        body;
  25. >                        while v <> temp2 do begin
  26. >                            v := succ (v);
  27. >                            body
  28. >                        end
  29. >                    end
  30. >                end
  31. >
  32. >where temp1 and temp2 are otherwise unused identifiers of the same type as
  33. >v (or, if v is a subrange type, of the host type of v's type), with the
  34. >restriction that no assignments to v are permitted within body.
  35.  
  36. Here's another difference between Turbo Pascal and the standard:  TP 
  37. implements the for as if temp1 and temp2 are of exactly the same type as v.  
  38. For example, if v is of type 1..10, then the standard won't complain about
  39.  
  40.   for v:=1 to 0 do...
  41.  
  42. but TP will give a range check error, because 0 can't be assigned to the 
  43. 1..10 subrange.
  44.  
  45. Duncan Murdoch
  46. dmurdoch@mast.queensu.ca
  47.