# While loop problem

Hi all, I am trying to create 2 lists using a while loop node, the idea is to take items from a list and keep adding these items until the total sum reaches 1 and this must be performed on the 2 sublists simultaneously
as a result, i must have a new list with a modified sublist but with the current graph, the while loop node keeps crashing or it is stuck in an infinite loop
any suggestion on how to fix while loop connection and am I using the right functions and argument?

Thanks alot, any help is really appreciated

I believe the LoopWhile input `init` is expecting a single value as the starting point. It’s not setup to loop through the whole (sub)list. Will your list of values always be one unique value or will they vary?

Hi Nick, first thank you for responding, you mean i should use only one item as input ? no i will have a several unique value because i will try to apply this loop algorithm to a list of surfaces most of these surfaces have the same area value but some are smaller

Why not just do mass addition, take the index of 1, and drop all indices after that?

Hi Jacob, how are you? Do you mean without using loop while node?

Yes - with a data set of this size there is no need to bother with the loop while.

This is almost always a better option.

There are many ways to get what you want. Here’s what I had in mind:

ah no this list was only a sample of what i am going to do i was trying to apply it on a small list to avoid crashing my script but, the original list will contains much more items (5000 ) it is about the same issue the 4m polygon but i convert the room into a grid of rectangles (pixels like )and trying to add these surfaces until it reach the 4 m2

Loops are best used for unknowns. If you have known values you can easily calculate the necessary outcome and then work backwards.

Thank you nick for the example above, unfortunately i guess i need a kind of algorithm, that is why i am trying to use loopwhile, basically what i am trying to do is to select a certain amount of indices from a list based on one constraint that the sum value of these items must be equal to 4 m2 ( the items are surfaces ) and i have to repeat this action based on the number of indices found in another list