Announcement

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

  • Incrementing over items of a list in a loop

    Dear all,


    I have the following problem
    I have a list of files that identify countries.
    In need to merge recursively each file with the remaining files in the list

    For example suppose the files are defined in the file list below

    local filelist "AT BE BG CY CZ DE DK"
    I need to merge the first file AT recursively with the subsequent files BE BG CY CZ DE DK
    Subsequently I need to merge the second file BE with the subsequent files BG CY CZ DE DK
    And so forth

    The problem is that I do not know how to move the index over a list which is not made by numbers
    If the list is made by numbers I would increment the loop by using ++`x’

    I tried using the macro `ferest()’ but for some reason it skips one position

    Here an example using instead of merge

    local filelist "AT BE BG CY CZ DE DK"

    foreach x of local filelist {
    display "`x'"
    display "`ferest()'"
    local filelist "`ferest()'"

    }

    What am I missing?
    Thank you in advance

  • #2
    I can only interpret the question as wanting an iteration over an expanding list of files.

    merge DE DK

    merge CZ DE DK

    merge CY CZ DE DK

    where each merge after the first is a merge of one file not seen before and another file produced by the previous merge.

    If that was the real problem, I might not write a loop at all but just crank out the 7 statements needed.

    But why this particular pair, triple, ... makes sense but not the others I can't follow. Why Denmark and Germany but not Denmark and Belgium, and so on?

    So, I probably am not understanding the question at all, or the question is a proxy for a different real question, or both.

    Comment


    • #3
      Dear Nick

      thanks for the reply. Probably my question was not sufficiently clear

      Suppose I have 4 countries DE, DK, CZ, CY

      I need to create 3 files (n-1 number of files)

      File 1:
      merge DE with DK, obtain DEDK
      merge DEDK with CZ obtain DEDKCZ
      merge DEDKCZ with CY obtain DEDKCZCY
      save DEDKCZCY

      Now drop from the list the first item (DE)

      File 2:
      merge DK with CZ obtain DKCZ
      merge DKCZ with CY obtain DKCZCY
      save DKCZCY

      Now drop from the list the second item (DK)

      ​​​​​​​File 3:
      merge CZ with CY obtain CZCY
      ​​​​​​​save CZCY

      I can do it by specifying several list., however I would like to automize the process as much as possible as I have more than 50 countries

      Comment


      • #4
        That looks like the same question to me. But you don't need so nearly so many merges

        CZ and CY

        DK and (CZ and CY)

        DE and (DK and CZ and CY).

        Comment

        Working...
        X