1

I have a for loop in which I would like to create list and add values to there.

FOR ${i} IN RANGE 3

*Create list List_${i}

  • Add values to list

END

How could I do it? So that after exit the for loop, I would have list_1 & list_2 and list_3

Meaning I can create dynamic variable like this:

FOR  ${idx}  IN RANGE  3
    ${var_name} =      Catenate  SEPARATOR=_  var      ${idx}
    Set Suite Variable  ${${var_name}}  ${idx}
END

Maybe it is some easy way to do the same with @list ?

This does not work:

FOR    ${i}    IN RANGE     3
    Log    ${i}
    ${var_name}=  Catenate  SEPARATOR=_  TEST_NAME  ${i}
    Log    ${var_name}
    @{${${var_name}}}=    Create List    data
END
1

2 Answers 2

1

I think this is the answer:

FOR    ${i}    IN RANGE     3
    Log    ${i}
    Set Suite Variable    @{List${i}}    @{EMPTY}
    Append To List    ${List${i}}    ${i}
END
Sign up to request clarification or add additional context in comments.

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
0

Note sure if this is exactly what you are looking for; but, I'll try to help. First, lists cannot be empty; so you will need at least an initial value which you can then remove (or ignore) when you iterate thru the list. That said, I can suggest you create a For-Loop which returns is List-of-Lists since your "loop range may change".

Test-Dynamic-Lists-Creation

${listOfLists}    Create List    initial-value
FOR    ${index}    IN RANGE    3
    ${List_$index}    Create List    initial-value
    Append To List    ${listOfLists}    ${List_$index}
END
Comment    Removes the first value from the list.
Remove From List    ${listOfLists}    ${0}
Log List    ${listOfLists}
Return From Keyword    ${listOfLists}

1 Comment

I intended to add the above code as a TEST which you could just copy/paste/save/run; but Stackoverflow did not allow me to publish it as such. Still, you should be able to copy this code into a test and run it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.