On Thu, 2015-04-30 at 18:37, Tom Breloff <[email protected]> wrote:
> I actually wonder if the bug is that Versions 1 and 4 *should* produce an 
> error, but they secretly work.  In your version 1:
>
> for i=1:2
>     if i>=2; println(z); end 
>     z="Hi" 
> end 
>
> z should be local to each iteration of the loop, so I think the second pass 
> should produce an undefined error. See from the manual:
>
> for loops and comprehensions have a special additional behavior: any new 
>> variables introduced in their body scopes are freshly allocated for each 
>> loop iteration. Therefore these constructs are similar to while loops with 
>> let blocks inside:
>
>
> Am I missing something?

Jeff says no: https://github.com/JuliaLang/julia/issues/11065

This works, but shouldn't:

for i=1:9
    if i==1
        j=1
    else
        j +=1
    end
    @show j
end

and this is what it should be equivalent to (and throws):

i= 1
while i<10
    let j
        if i==1
            j=1
        else
            j +=1
        end
        @show j
    end
    i+=1
end


> On Thursday, April 30, 2015 at 9:40:29 AM UTC-4, Sisyphuss wrote:
>>
>> I filed an issue: https://github.com/JuliaLang/julia/issues/11065
>>
>>
>>>

Reply via email to