Do you have a clean way of looping through an array?

Post it here. And when I say clean, it doesn’t mean clever. (I usually find that the clever ways of doing things are not the most legible.)

Could you clarify what kind of an array?

a = Array{Float64,3}(undef,3,3,3)
for i in eachindex(a)
    element = a[i]
1 Like

I try to follow the manual when possible:

Some would also recommend pairs which returns the index and the value.


I like eachindex too!

pairs seems to be more robust than enumerate. That is my impression.

This has been discussed here: Any shortcut to 1:length(myVector)?

1 Like

I never used pairs, but it seems it is a bit more flexible in regards to the index. enumerate always uses a one based linear index.

1 Like