Nested For Loops in Design Script Impertitive Blocks

I know nested for loops isn’t the best of practice but I’m not in need of any hardcore optimization yet but could really use the flexibility of design script here.

I’m trying to develop a list of lists so that I can do further processing on the points but I’ve been unable to get the imperative block to output anything. Besides researching forums posts here about imperative blocks, I’ve also tried to reconfigure it many ways in case I’m mistaken in how to develop lists of lists but everything keeps outputting Empty List.

You use nested for loops for a purpose and there are many reasons why you would use them…like traversing or constructing a 2D list for example. There is no such thing as ‘best practice’ in that regard. The most common mistake is improper use, like using a while loop when a for loop should be used/is better.

Anyway, Dynamo’s wonderful List class is static, so when you call the AddItemToEnd() method you need to assign it to something otherwise you have no pointer to the result and effectively lose it with each iteration, which is why you’re seeing no output. In your case it will be set = List.AddItemToEnd(… in the inner loop and setofsets = List.AddItemToEnd(… in the outer loop. Bizarre, counter-intuitive syntax, but the world is an imperfect place :wink:


Oh my goodness. Thank you so much @Thomas_Mahon . Not sure I would have ever gotten to that configuration myself. (See attached) As my Python programming skills develop - and I learn to love Python - I’m having a lot of trouble understanding where Python ends and DesignScript begins.