Why FOR Loop last iteration ITEM not available GLOBALLY?

Thanks man… I got it…

for i in 1:8897979797897897
    try
        Char(i)
        continue
    catch
        println("Inside Loop",i)
        global x = i
        break
    end
end
println("Outside Loop",x)

As stillyslalom says:

"In general, it’s best to avoid global scope, and you could instead write a function that returns the error-producing i "

i.e.,

function errorchar(limit)
    for i in 1:limit
        try
            Char(i)
        catch 
            return i
        end
    end
end

Thank you very much Jeff_Emmanuel & stillyslalom

2 Likes