[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: continue/repeat...until false dichotomy
- From: Matthew Wild <mwild1@...>
- Date: Wed, 17 Feb 2010 00:42:34 +0000
On 17 February 2010 00:25, Kelley, Brian <email@example.com> wrote:
> On Feb 16, 2010, at 3:40 PM, Matthew Wild wrote:
>> On 16 February 2010 22:24, Kelley, Brian <firstname.lastname@example.org> wrote:
>>> On Feb 16, 2010, at 1:44 PM, Florian Weimer wrote:
>>> Make it:
>>> Â Âlocal t = 0
>>> Â Âif cond then continue end
>>> Â Âlocal t = 1
>>> Â Â...
>>> Âuntil t == 0
>>> Then the two t are actually different variables (in the current
>>> implementation), and it's not clear to which incarnation the
>>> comparison refers.
>>> Why is it not clear? ÂWould it be clearer without the continue statement?
>>> The continue statement does not impact the *scope* of variables. ÂScoping is
>>> lexical -- as written. ÂContinue is just a restricted 'goto'.
>> If it's so clear, what is the behaviour of the code above?
> Assuming "variables default to nil", when 'cond' is true and the continue is taken, "t==0" will evaluate to false because 't' will be nil.
> I'm not sure what is throwing you off. ÂEach "local t" declares a new variable. ÂHere is an illustration of that:
Right, but the "local t" that declares the t used in the loop
condition was never hit.
> local t
> local function get() return t end
> local t
> local function set(a) t = a end
> print(get()) Â--> Ânil
I don't find this confusing at all, it's perfectly logical. But
jumping over local statements and then having the variable magically
exist is logically wrong :)