Re: trace(1) bug

new topic     » goto parent     » topic index » view thread      » older message » newer message

Andy Drummond wrote:
> 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
> Why do you want this to goof?

Because it's a mistake. In this case, I did not intend to overwrite the
'i' variable; I did it on accident.

> 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.

Right now the interpreter protects programmers from making this mistake. If
you want to be able to use an already-declared variable in a for loop, make
a new way to iterate. Don't mess with for...end for!

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu