Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Looping over two locals at the same time?

    Dear all

    Suppose i have two lists stored in two different locals:

    list1 one two three four five
    list2 six seven eight nine ten

    I would like to loop over each list but the loop is like 50 lines long. I was wondering if it is possible to loop over both locals at the same time? And store "results" relating to each list separately?

    Code:
    foreach x of local list1 list2 {
    .
    .
    .
    local result1 = one1 two1 three1 four1 five1
    local result2 = six2 seven2 eight2 nine2 ten2
    }
    Or is there another way of doing this without looping?

    Thank you.

  • #2
    Your specific syntax is illegal as foreach only allows one local: see the help.

    If it makes sense otherwise, you could go

    Code:
    foreach x in `list1' `list2' { 
    }
    or

    Code:
    local list `list1' `list2'  
    
    foreach x of local list { 
    
    }

    Comment


    • #3
      Thanks Nick. I am aware that this syntax is illegal but this is the fastest implementation and i was wondering if there was an equally good way to do what i want. Also, how can i know when the loop changes from list1 to list2 so i can save the results in different locals?

      Comment


      • #4
        If you want two loops you can have them. I thought you were asking for one. Also, if you know that something is illegal, do say.

        Code:
        forval i = 1/2 
                foreach x of local list`i' { 
        
                } 
        }

        Comment

        Working...
        X