Reputation: 502
I have two list variables @{vinrange}
and @{sg}
both with same dimensions of 4
I want to print into the LOG
using the scalar ${VAR1}
for each value from the list variable @{vinrange}
and print using a second scalar ${VAR2}
for each value from the list variable @{sg}
I have to assign both of them into the same loop, the ${VAR1}[1]
has worked for the @{vinrange}
, however, I don't know how to do for the second list variable @{sg}
.
Upvotes: 3
Views: 7192
Reputation: 20067
There is a FOR
construct version precisely for this situation - to iterate over two lists simultaneously - that is with IN ZIP
, link to the documentation .
It expects two or more iterables (like lists), and on every iteration returns the values of each at the same index.
Note that it will stop at the shorter one's last element (e.g. if their lengths are different, it won't raise an exception, nor it will fully exhaust the longer list). So for your case:
FOR ${vinrange_element} ${sg element} IN ZIP ${vinrange} ${sg}
Log ${vinrange element}
Log ${sg element}
END
Upvotes: 6
Reputation: 741
A Generic Context of For Loop in robot framework is
FOR ${item} IN @{ITEMS}
${item} Arg2
END
Example-
FOR ${index} IN RANGE 42
1st arg ${index}
END
Upvotes: 0
Reputation: 1709
Try to count your list by use Get Count
than FOR LOOP
and log by using Iterator ${i}.
Here sample for you
${length}= Get Count ${vinrange}
FOR ${i} IN RANGE 1 ${length}
Log ${vinrange}[${i}]
Log ${sg}[${i}]
END
Upvotes: 3