3 ms·
> Is "for i in 1:length(A)" ever correct? Yes, actually. While I have approximately zero knownledge of Julia specifically, a language-independent example might
by a1369209993 4y ago
> Is "for i in 1:length(A)" ever correct?
Yes, actually. While I have approximately zero knownledge of Julia specifically, a language-independent example might be:
B = OneBasedArray(length(A))
A_ = iter(A)
for i in 1:length(A) { B[i] = pop(A_) }
assert(iter_isdone(A_))
And if that looks contrived... yes; it is contrived.
> that pattern followed by usage of i to index into A inside the loop?
I can't think of any legitimate uses for that, but there probably are some; make sure to allow:
len = length(A)
for i in 1:len ...
as a `if( (x = foo()) )`-style workaround.