Can anyone please help me understand the working of a While loop? Please review the two screen captures below. By including a list as an argument for a function, the return of the functions changes, although the list input is not used anywhere in the algorithm, either in the While loop, or the Imperative block.
Thanks.

Hi Aseem,
I believe it’s because in the first case it iterates through only a single input. In the second case it iterates through a list as well(multiple inputs), and thus gives you the result for every item in the list.( i.e. every “in” has an “out”, even if you’re not using it anywhere it in the code.) Hope that clears it up.

The forum misbehaves sometimes. Here’s the image again:

On your second point, I believe that your approach is correct. You will need to create a definition with defined variables, so if you’re feeding a list of inputs, it might help if you use
“def Function(input:var)” to tell the code block to iterate through the whole list instead through each member of the list individually.
I had some difficulties understanding the loop while approach in Dynamo as well. Michael Kirschner helped me with that here:
http://dynamobim.com/forums/topic/the-misterious-loopwhile-node/
Good luck!
Dimitar,
Can you please give me an example of what you said -
"You will need to create a definition with defined variables, so if you’re feeding a list of inputs, it might help if you use
“def Function(input:var)” to tell the code block to iterate through the whole list instead through each member of the list individually."
I am having trouble getting that to work.
Thanks.
I’ll try to explain it with a quick example. It is a pretty basic function with 2 variables. I’ve repeated it 4 times and in each case the only difference is the definition of the input variables.
So in the first case the function knows to expect two lists. Everything works as expected. The while function evaluates the first list. The first list is longer and that is why the last index of the result is null - because the second list doesn’t have a corresponding index.
In the second case neither of the input parameters are defined. Therefore each element from your input lists is evaluated on its own and because it’s a non-list single element, you get null values when you try to index it.
In the last two cases either one of the two input parameters is defined as a list. The function fails in both cases because you are trying to index a non-list single element again. However it’s interesting to note that the output is formatted differently because your input parameters are not the same length and that affects the lacing of the output.

I hope I didn’t confuse you more. Maybe someone will come up with a better example than this.
Dimitar,
That was extremely helpful! That made complete sense, and I have got my graph working that way I wanted.
I appreciate you taking the time to put that example together for me.