Path: utzoo!attcan!uunet!ncrlnk!ncrcae!hubcap!gatech!uflorida!haven!adm!xadmx!abcscnuk%CSUNA.UUCP@cunyvm.cuny.edu From: abcscnuk%CSUNA.UUCP@cunyvm.cuny.edu (Naoto Kimura) Newsgroups: comp.lang.pascal Subject: Control variables in FOR loops Message-ID: <17843@adm.BRL.MIL> Date: 16 Dec 88 19:18:10 GMT Sender: news@adm.BRL.MIL Lines: 51 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 !!