Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!shelby!agate!dog.ee.lbl.gov!elf.ee.lbl.gov!torek From: torek@elf.ee.lbl.gov (Chris Torek) Newsgroups: comp.lang.c Subject: Re: Help with casts Message-ID: <10257@dog.ee.lbl.gov> Date: 25 Feb 91 20:11:59 GMT References: <1991Feb21.040145.8678@cec1.wustl.edu> <409@ceco.ceco.com> <339@smds.UUCP> <414@ceco.ceco.com> <1991Feb25.143544.11950@watdragon.waterloo.edu> Reply-To: torek@elf.ee.lbl.gov (Chris Torek) Followup-To: comp.lang.pascal Organization: Lawrence Berkeley Laboratory, Berkeley Lines: 49 X-Local-Date: Mon, 25 Feb 91 12:12:00 PST In an article whose referent has been deleted (perhaps <414@ceco.cecom.com>?) Garry Garrett writes: >>For instance, in pascal the index of a for loop cannot be referenced >>outside of that loop ... In article <1991Feb25.143544.11950@watdragon.waterloo.edu> dsebbo@dahlia.uwaterloo.ca (David Ebbo) writes: >No. In Pascal, you can use any integer variable as a for loop index, and it >can be referenced outside the loop. Garry Garrett is correct. Pascal (at least `old' Pascal; I have not kept up with the ISO variants) makes three constraints on loop index variables: - they must be local; - they may not be altered inside the loop; - they may not be examined outside the loop. Many compilers do not enforce these restrictions, but program foo; var i : integer; procedure nothing; begin end; begin for i := 1 to 10 do nothing end. is illegal because `i' is global; procedure bar; var i : integer; begin for i := 1 to 10 do i := 3 end; is illegal because `i' is altered inside the loop; and procedure baz; var i : integer; begin for i := 1 to 5 do nothing; writeln('i=5? i=', i) end; is illegal because `i' is used outside the loop without first being redefined. Changing baz to: procedure baz; var i : integer; begin for i := 1 to 5 do nothing; i := 5; writeln('i=', i) end; makes it legal. -- In-Real-Life: Chris Torek, Lawrence Berkeley Lab EE div (+1 415 486 5427) Berkeley, CA Domain: torek@ee.lbl.gov