LoopWhile and Functions

Hi!

I am struggling and hoping someone is able to help.

I am trying to make a list where the next number in the list is based off the number before it. Specifically, I have three numbers (1,2,3), and I want the next number in the sequence not to be the previous number, and random between the other two. I also want this to stop at a specific number, and I think I have that part figured out.

My thinking is that I use 'List.LastItem" to get the last number in the list and plug that into ‘SetDifference’ to find the two numbers not used and then shuffle and grab the first number. Then with that number add it to the end of the list with LoopWhile. There seems to be some disconnect and I am thinking it is because I did not set up the function correctly.

.

Any thing you can do to help is much appreciated!

-J

your loop body is incorrect I think. Try using a custom node instead, so it is very obvious what function is being run.

Please give sample output

Sorry I did not add the the function results.

So what is happening is that it is not including the List.LastItem in the function. It is figuring out the number just one time (2), and then adding it to the end of the list for the duration of the LoopWhile.

Michael, I am not exactly sure how I would custom node this, do you have any ideas?

Thanks again.

take your entire loop body and make it a custom node. - the issue is that you have two functions for your loop body, you need a single function that takes one input and returns a single output. (in your case a list)…

What is the result supposed to be?

It worked!

Making the loopBody a Custom Node and then making the list the input worked. Thanks for your help Michael, it is much appreciated.

1 Like