RosettaCodeData/Task/Loop-over-multiple-arrays-simultaneously/Picat/loop-over-multiple-arrays-simultaneously.picat
2023-07-01 13:44:08 -04:00

25 lines
550 B
Text

import util.
go =>
L1 = ["a","b","c"],
L2 = ["A","B","C"],
L3 = ["1","2","3"],
println("foreach loop:"),
foreach({A,B,C} in zip(L1,L2,L3))
println([A,B,C].join(''))
end,
nl,
println("list comprehension/n:"),
println( [[A,B,C].join('') : {A,B,C} in zip(L1,L2,L3)].join("\n")),
nl,
% With uneven lengths the last elements in the longer lists are skipped.
println("Uneven lengths:"),
L4 = ["P","Q","R","S"], % longer than the other
foreach({A,B,C,D} in zip(L1,L2,L3,L4))
println([A,B,C,D].join(''))
end,
nl.