Loop (i, j) without zip() stopped at the 2nd round

JiuuJulia
Tue, 16 Aug 2022 06:16:44 +0000
General Usage

I’m trying to loop two DNA sequences:

a = "AAAGCTAGCTAGCTAGACT"
b = "ATAGCTAGCCAGCTAAACT"

for (i, j) in (a,b)
    println(i, j)
end

It gives a result:

AA
AT

Why does the loop stop at the 2nd iteration?

I know I’d better do it with zip() as :

for (i, j) in zip(a,b)
    println(i, j)
end

and it gave the right answer.

AA
AT
AA
GG
CC
TT
AA
GG
CC
TC
AA
GG
CC
TT
AA
GA
AA
CC
TT

But still, I don’t understand why iteration stopped at the 2nd round without zip(), and it didn’t raise any error! Does anyone have any ideas? I can’t find the answer in the doc (or I didn’t go to the right place)

Julia version:

v"1.7.3"

Interesting approaches:

rafael.guerra:

foreach(println, a, b)

Nathan_Boyer:

for i in eachindex(a)
    println(a[i], b[I])
end

10 posts - 5 participants