LoopWhile in action!

I always did wonder how to use a LoopWhile Node for complex functions without crashing. Top Google result leads to this mysterious post. Some users here have gotten it to work, as I have in the past, but I kept struggling with getting it right every time. Getting it wrong often resulted in Dynamo (and Revit) locked in an infinite loop. The key for me is to carefully write a Custom Node specifically designed to work with LoopWhile as ‘loopBody’ function, use an extremely simple function for the ‘continueWhile’ input, and wrap that in another Custom Node.
The benefit of putting all the complexity in one function is that the function can be tested by simply stringing a lot of them together and feeding it the intended input directly, even before wrapping the function in a Custom Node. Now you have a test environment that will never get stuck in a loop and shows you exactly what happens at each iteration. EDIT: @Dimitar_Venkov did something like that here. Always turns up right after you post doesn’t it.
Before feeding the input in the ‘init’ port, the input is preceeded with a ‘true’ value and followed with an empty list. The loopBody function processes each item in the input and places it in the empty list. Finally, the function evaluates if another iteration is called for and writes that to a bool in the first index, replacing the original bool value.

See attachments for a very generic implementation, joining overlapping lists. Normally this would have required some imperative DesignScript or Python (still learning).

JoinNestedListsByOverlap

JoinNestedListsByOverlap.dyf (6.0 KB)
JoinNestedListsByOverlapFunction.dyf (18.5 KB)

4 Likes