< Back to IRCAM Forum

While loop and accumulator

Case description:

On the accumulator:

data input : 5
init: 2
fun: lambda patch. data input (5) - init (2)

On the while:
While connected to an om>= 3

The loop I need is to keep substracting the accumulated value (and outputting the result of each iteration). That would be:

First iteration:
5 - 2 = 3
output 3

Second iteration:
3 - 2 = 1
output 1

I don’t get this result.

My question is: where in the accumulator do I have to connect the om>= conditional (which is connected to the while) ?

Here you are:


1 Like

Ok, it works. I thought I had to follow the description in the reference document, which says:

“data should be connected to the data to collect.
init determines the initial value of the accumulator.”

Data as in a number or a list. That’s what I understand.
And init a fixed number.

But your example shows otherwise, it’s fine by me, I’ll switch connections and that should work.

this is exactly what Karim’s example patch does. a list as data in this case won’t work because it’s using a >= predicate (an integer can’t be >= of a list).
the init value is 9 and the loop is subtracting 2 on each iteration till it meets the while condition.
hope this helps,

1 Like

How to do the same but with a list?

I have been trying for two days how to do it with a list, connected to the input of the loop from an external textfile. Do you know how to input a list in a loop, substract and outputting the result each iteration?

hello archiduque,

where do you want to input a list? please be more specific.
you can do lots of things in a loop and of course lists can be used as input, but any function you use in it must be capable of accepting lists as arguments. Karim’s example use >= for the whileloop and this functions only takes numbers as input. so a list, instead of a number, will return an error.
I’m not sure I understand what you’re looking for, but if you want to use this patch with a list as input, you may include it in another loop, using listloop.
I would like to attach a MWE but I need to fully understand your goals first.

Ok, there’s no way.

That was one of the options as well, I am trying that.

Using Karim’s example, I want to input a list of numbers, instead of a single number.

2021-08-01 23_02_01-^prueba 2° algo 3

Now in this example picture I uploaded (the loop is the same as Karim’s I just change the condition for the while and the list’s numbers) I have a list of 3 and 2.
I want the loop to keep on substracting 1 and outputting the result of each substraction on the lower textfile until the condition =0
I don’t want to stop when the 2 of the first list comes to the iteration, that would leave a result of 1.
I want that resulting 1 to be substracted with a 1 as well, resulting in the 0 of the condition.
Each iteration must output the result.

Hi A.

You cannot pass a list to >=. But if i understood you well (very difficult here :-)) you need to stop your calculations whenever you reach a non-negative number? So this is maybe what you are looking for:


What I need is the first example you posted before, but with lists. I realized it is not possible, then perti confirmed it, and so did you. Nevermind, I will close this thread.

With lists? can you give an example please?

I’m sorry archiduque but no, I didn’t confirmed that that was not possible. I only said that in Karim’s example the >= function will not take lists as arguments. this doesn’t mean there’s not a way to find a solution. it was only that you expressed the problem in a way I couldn’t fully understand.
anyway (and now I’m guessing), if what you need is a loop inside a loop, see the pic, within is Karim’s example with little modifications embedded in another trivial loop. of course this will need more adjustments, like that one for avoiding negative numbers…

Thanx Perti.

However, i begin to doubt that this is what A is after. A clear explanation from archiduque is most welcomed.