Re: trace(1) bug
- Posted by Andy Drummond <andy at ?estrel?ele.com> Nov 15, 2007
- 550 views
c.k.lester wrote: > > Andy Drummond wrote: > > > My personal preference - if worth anything - is that if a variable > > has been declared when used in a for loop, then that variable is used. > > Then it is in scope after the loop exits. If no such variable has > > been declared then it is a local to the loop and out of scope as soon > > as the loop exits. This seems entirely consistent with the normal > > practise of variable scoping when functions are defined.... > > Please, no. I want this to be a goof: > > integer i > i = find(x,y) -- i is now 32 > for j = 1 to 10 do > for k = 1 to 10 do > for i = 1 to 10 do -- DO NOT ALLOW > ... > end for > end for > end for > > ?i -- better be 32 Heck, I'm not doing this at all well. Why do you want this to goof? If I have a function with local variables, they are only local. If I refer to a variable I didn't declare locally and it was declared globally I'd use that. And no matter how deep the nesting, the locals could all be the same name - all i if you like. If you used a routine-global variable in more than one nested loop you would expect horrible results - but you might want that. At present it is not legit so no code would be broken. So why you expect the i to remain 32 after changing it in a for-loop? If you had wanted the for-loop iterator to be different then call it something different. It seems unreasonable to have a variable in scope, changed, and yet to preserve an earlier value. In current terms the DO NOT ALLOW would have prevented any code to be written which would foul the value of i, but new coding could use a variable in a loop iterator and yet access it after the loop. Sounds great to me but .... Matt - I am missing something fundamental if you disagree - what is it? AndyD