Using this for loop with using ProgressMeter:
function test()
@showprogress 1 "Computing..." for n in 3:5:20
print()
end
end
I don't understand why @code_warntype test() returns at three lines a type warning and most importantly how to fix it:
%18 = φ (#2 => %12, #3 => %14)::Union{Nothing, Tuple{Int64,Int64}}
This is how for-loops work internally in Julia, there is nothing you need to worry about or fix here, see https://docs.julialang.org/en/v1/manual/interfaces/#man-interface-iteration-1.
In particular, for-loops call iterate on the object you iterate over, and return nothing if the iterator is done, or a tuple with loopvariable, state. For this particular case, iterate of a StepRange{Int,Int} you thus get back Union{Nothing, Tuple{Int,Int}} from the iterate call:
julia> @code_warntype iterate(3:5:20)
Body::Union{Nothing, Tuple{Int64,Int64}}
[...]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With