Loop through list in C#

In my definition I’m trying to create a C# script that loops through a list of numbers (such as 1 - 100) that increments by 10. After the series of numbers has reached 100, I want to restart at the next first number in the list and keep looping until every number in the 1-100 list has been accounted for.

At the moment, the group of components with multiple series is working exactly how I want the definition to work, but it’s inefficient.

The C# script I created is kind of working, but it doesn’t restart at the first number after its counted through the list. Here is the code for the C# script:

    int listLength = 100;
    int stepSize = 10;

    int amountOfBranches = listLength / stepSize;

    DataTree<int> tree = new DataTree<int>();

    int count = 0;


    for (int i = 0; i < amountOfBranches; i++) 
    {
      // Print(i.ToString());
      GH_Path path = new GH_Path(i);

      for(int j = 0; j < listLength; j += stepSize)
      {
        tree.Add(count, path);
        count += stepSize;
      }
    }

    A = tree;

Any insight or advice would be greatly appreciated.

loopThroughList_V1.gh (9.1 KB)

It looks like you just need to set a new value for “count” at the end of the i for-loop.

So the last line would I assume be:

for (int i = 0; i < amountOfBranches; i++) 
    {
      // Print(i.ToString());
      GH_Path path = new GH_Path(i);

      for(int j = 0; j < listLength; j += stepSize)
      {
        tree.Add(count, path);
        count += stepSize;
      }
      count = i+1;
    }

-Sash

Using standard components:


loopThroughList_2021Dec27a.gh (14.7 KB)

Both of the answers listed above are great. Thank you Sash and thank you Joseph for providing an alternative approach with out C#.