🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #5439

Re: Loops

#5439
From: Bob Dietrich
Date: Mon, 11 Apr 1988 21:32
69 lines
3029 bytes
In article <11047@shemp.CS.UCLA.EDU> gast@lanai.UUCP (David Gast) writes:
>While it is commonly believed that it is impossible to change the
>index variable in a for loop, it is possible to do so.  Consider the
>following program.

Sorry, but the existing ANSI/IEEE and ISO Pascal standards do not allow such
modification. There is a concept called "threatening" explained under the
for-statement (section 6.8.3.9). Basically, if a variable has been
"threatened", it cannot be used as a for control variable. A variable is
threatened when it appears as the target of an assignment, as a variable
parameter, as the non-file parameter of read or readln, or if a statement
enclosing the for-statement has the same control variable (a for-statement
nested within a for-statement). These restrictions apply to routines nested
within the current routine as well. This check can be done at translation
(compile) time, and requires only a Boolean flag for variables that can be a
for control.

>
>program illegal (output);
>
>{This program is not legal pascal, but the compiler does not detect the
> error.  If the scope of the index variable were local to the for loop
> (ala Algol 68), instead of global, then this error would be detected
> at compiler time. } 
>
>	var
>		i : integer;
>
>        procedure illegal_assignment (k: integer);
>			begin
>				i := k + 10;  {i is the index variable in the for loop}
                                ^-- a threat to i (all it takes is one!)

>				writeln (i)
>			end;
>
>	begin
>        for i := 1 to 10 do
             ^-- At this point threats to i are checked, and the violation
	     detected.

>			begin
>				illegal_assignment (i);
>				writeln (i)
>			end
>	end.
>	
>Although I have not read the latest Pascal standard, the Pascal I used
>has many insecurities.

This may well be, and is unfortunate. However, please try to separate the 
language from your particular implementation. Like any other language or
tool, there's mediocre implemententations and excellent implementations, and
a lot in-between. Speaking as both a compiler writer and a user, I suggest
you beat on your vendor to get rid of the insecurities that are giving you
problems, or take your business elsewhere if they don't respond.

>
>David Gast
>gast@cs.ucla.edu
>{ucbvax,rutgers}!ucla-cs!gast


				Bob Dietrich
				Intel Corporation, Hillsboro, Oregon
				(503) 696-4400 or 2092(messages x4188,2111)
		usenet:		tektronix!ogcvax!omepd!bobdi
		  or		tektronix!psu-cs!omepd!bobdi
		  or		ihnp4!verdix!omepd!bobdi
Technical Details
Message-ID: <3364@omepd>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!littlei!intelisc!omepd!bobdi
References: <2827@enea.se> <1557@pasteur.Berkeley.Edu> <2773@mmintl.UUCP> <294@tmsoft.UUCP> <11047@shemp.CS.UCLA.EDU>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!littlei!intelisc!omepd!bobdi
From: bobdi@omepd (Bob Dietrich)
Newsgroups: comp.lang.misc,comp.lang.pascal
Subject: Re: Loops
Message-ID: <3364@omepd>
Date: 11 Apr 88 21:32:04 GMT
References: <2827@enea.se> <1557@pasteur.Berkeley.Edu> <2773@mmintl.UUCP> <294@tmsoft.UUCP> <11047@shemp.CS.UCLA.EDU>
Reply-To: bobdi@omepd.UUCP (Bob Dietrich)
Organization: Intel Corp., Hillsboro, Oregon
Lines: 69