Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!mailrus!tut.cis.ohio-state.edu!cs.utexas.edu!sm.unisys.com!csun!csuna!abcscnuk From: abcscnuk@csuna.UUCP (Naoto Kimura) Newsgroups: comp.lang.pascal Subject: Control variables in FOR loops Message-ID: <1439@csuna.UUCP> Date: 14 Dec 88 02:31:16 GMT Reply-To: abcscnuk@csun.UUCP (Naoto Kimura) Organization: California State University, Northridge Lines: 50 I have gotten into some pretty heated discussions regarding the control variable in a for loop. I was arguing that it was a bad idea to use a global variable, in fact it is an error to do so. I'm arguing from the ISO standard, while the people I was arguing against were going by specific implementations that allowed it. Should the use of a relatively global variable be allowed as a control variable for a for loop ? Should the use of a passed parameter be allowed as a control variable ? I say no to both of these. One person that I got into an argument with said that the behavior should be that you can change a control variable, but should not have any effect on the loop itself. I don't think that is reasonable. Consider the confusion over what the variable 'i' should contain when you use it in several procedures as control variables for a for loop. I'd like to know how you feel about the behavior of the following program. What should the output be (if the compiler even lets this code through) ? program nonsense(input,output); var i : integer; procedure barf; begin for i := 1 to 10 do write(i:3); write(' i=',i) end; procedure ack; begin for i := 1 to 10 do begin write('i=',i:2,' '); barf; writeln end end; begin for i := 1 to 10 do ack end. //-n-\\ Naoto Kimura _____---=======---_____ (csun!csuna!abcscnuk) ====____\ /.. ..\ /____==== // ---\__O__/--- \\ Enterprise... Surrender or we'll \_\ /_/ send back your *&^$% tribbles !!