Path: utzoo!attcan!uunet!husc6!mailrus!csd4.milw.wisc.edu!markh From: markh@csd4.milw.wisc.edu (Mark William Hopkins) Newsgroups: comp.lang.pascal Subject: Re: Control variables in FOR loops Message-ID: <57@csd4.milw.wisc.edu> Date: 23 Dec 88 02:01:56 GMT References: <1439@csuna.UUCP> <45@csd4.milw.wisc.edu> <1771@buengc.BU.EDU> Sender: news@csd4.milw.wisc.edu Reply-To: markh@csd4.milw.wisc.edu (Mark William Hopkins) Organization: University of Wisconsin-Milwaukee Lines: 32 In article <1771@buengc.BU.EDU> art@buengc.bu.edu (A. R. Thompson) writes: >In article <45@csd4.milw.wisc.edu> markh@csd4.milw.wisc.edu (Mark William Hopkins) writes: >> >>for I := A to B do S equals I := A; >> while I <= B do begin >> S; >> if I < B then I := succ(I) >> end >> : > >Ah, but since you've already established that it's an illegal program you >can no longer predict what will happen. That's strictly up to the >compiler writer (who is duty bound to report the error and refuse to >generate executable code). Secondarily, while your definition is the >proper way to define the effect of the for statement it allows the control >variable to be defined after completion of the while statement. The >control variable is required to be undefined upon completion of the for >statement. The point I was making is that it is much easier on all counts to define the for loop as a while loop and not place any restrictions on the control variable. The real problem with the program example brought up previously was that it used global variables, and I don't think Pascal should have allowed for them at all. The for loop was merely a red herring.