For loop - adding diferent sublists

Hello,
I’m quite new in programming (at all levels). I’m trying to jump from nodes to DesignScript to improve some of my scripts.

I’m getting stuck with a simple for loop (I think, but my level it is what it is) and I don’t get how to get around this.

I’m trying to simplify this definition with for loop:

list1= [[“a”,“d”],[“b”,“e”],[“c”,“f”]];
list1[0];
nestedList1=[
(list1[0]<1>+list1[1]),
(list1[0]<1>+list1[2])
];

nestedList2=[
(list1[1]<1>+list1[2])
];

DSCore.List.Flatten([nestedList1,nestedList2]);

What I’m trying to do, it’s simplifying that code with a for loop, but there is something that maybe I’m not understanding in the way of getting the results from the for loop.

list1= [[“a”,“d”],[“b”,“e”],[“c”,“f”]];
iListCount = DSCore.List.Count(list1@L2) -1;
iList=iListCount-1;

[Imperative]
{
result = ;
for (i in 0…iList)
{
result = (list1[i]<1>) + (list1[i+1…iListCount]);
}
return = result;
};

When I finish this code I get an error: Imperative factor not valid.
I didn’t used the flatten here, because I couldn’t get further before getting the result in sublists.

Probably it’s a silly issue that I’m not considering or I haven’t understood correctly in the data list structure.

I hope someone can help me to get across this little rock.

Thank you in advance.

first thing is that you cannot use replication or replication guides inside an imperative block.

1 Like

Thank you, didn’t noticed about replication and levels in imperative.

Just accomplished with this code:

list1= [[“a”,“d”],[“b”,“e”],[“c”,“f”]];
iListCount = DSCore.List.Count(list1@L2) -1;
iList=iListCount-1;

resultEnd=[Imperative]
{

  • result = ;*
  • for (i in 0…iList)*
  •   {*
    
  •   for (j in 0..iList)*
    
  •   	{*
    
  •   	result[i][j] = [list1[i][j] + list1[i+1][j],list1[i][j]+list1[i+1][j-1],list1[i][j] + list1[i+2][j],list1[i][j]+list1[i+2][j-1]];*
    
  •   	}*
    
  •   }*
    

return = result;
};
flatList=DSCore.List.Flatten(resultEnd);
mask=flatList@L1==null;
endList=DSCore.List.FilterByBoolMask(flatList,mask);
endList[“out”];
DSCore.List.Sort(endList[“out”]);