Path: utzoo!attcan!uunet!tektronix!percival!qiclab!m2xenix!randy From: randy@m2xenix.UUCP (Randy Bush) Newsgroups: comp.lang.pascal Subject: Re: Control variables in FOR loops Message-ID: <170@m2xenix.UUCP> Date: 21 Dec 88 06:33:24 GMT References: <1439@csuna.UUCP> <169@m2xenix.UUCP> <1712@buengc.BU.EDU> Reply-To: randy@m2xenix.UUCP (Randy Bush) Organization: Oregon Software, Portland Oregon US Lines: 34 In article <1712@buengc.BU.EDU> art@buengc.bu.edu (A. R. Thompson) writes: >In article <169@m2xenix.UUCP> randy@m2xenix.UUCP (Randy Bush) writes: >>The interesting, and unexpected, restriction is that it may not be threatened >>by use within an enclosed procedure/function. The following is not legal: > >If you want to make assigning references to the control variable in a looping >statement, you should use either a while statement or a repeat statement. >That's what they are for (so to speak). Please peruse the example again. There was no assignment to the control variable during the dynamic execution of the FOR statement. In fact, the procedure containing the threat is never called, nor is there any code in the FOR's statement sequence. The restriction on 'threatening' (to forbid what is actually a non-threat) in the example is a sop to the compiler writer. Without the restriction, it is easy (albeit ugly) to write real threats that are quite hard to detect. Again, (a simpler case of) the illegal example: PROGRAM foo; VAR i : INTEGER; PROCEDURE fee; BEGIN i := 42 (* this illegal assignment 'threatens' i *) END (* fee *); BEGIN (* foo *) (* whereas i := 42 here would be legal *) FOR i := 0 TO 42 DO END. BTW, the ISO Modula-2 committee is leaning toward a similar position. -- { mcvax!uunet!oresoft, tektronix!percival!qiclab } !m2xenix!randy Randy Bush