• ### [loop]: a sophisticated vanilla loop abstraction

[loop] is a sophisticated abstraction based on [until] that creates a loop with a counter.
You can set predefined arguments for start and end values. If you use only one argument, it will set the number of iterations and the counting will start from 0. If your end value is 0, you must use a third, non-zero argument in order for the abstraction to work properly.

If you set no arguments, you can send a number to its left inlet which will set the number of iterations, or a bang, but you need to send a bang to its rightmost inlet at some point, to avoid crashing Pd.

You can also create backwards counting loops, and can also include negative numbers in your counter.
It also sends a bang out its left outlet when the loop has finished.
check help patch for information.

loop.zip

• | Posts 6 | Views 4254
• Really nice object, Alexandros, super handy! It's only a pity that [loop 3 0] doesn't work and it needs that third argument hack, would you be able to explain why is that? Also, you do mention in your helpfile that the fourth inlet takes a bang to stop the loop, but maybe it would be better to add an algorithmic example of that (you know how people are with text vs visual information - TL;DR, right?)

Thanks for sharing and take care,
Gilberto

• @gsagostinho the third argument is necessary cause I couldn't think of a way, in case only one argument is provided, to use that to set the number of iterations and not the beginning of the count. If \$2 is zero, then \$1 goes straight to [until]. But \$2 will be zero in both cases where a 0 argument is provided, but also if no second argument is provided. So I thought of inserting a third argument and doing a Boolean OR to see if a second argument with the value 0 is indeed provided. If you, or anyone else, can come up with a solution, I'd be glad.

Thanks for pointing out adding an example of stopping the loop with a bang (with defined arguments, there is already an example with no arguments). It's in the new .zip file.
loop.zip

Cheers,
Alexandros

• Thanks for pointing out adding an example of stopping the loop with a bang (with defined arguments, there is already an example with no arguments)

You are very polite, Alexandros: my suggestion was actually rubbish, I didn't realize that there was already one example showing how to use the fourth inlet (thus I myself can suffer from TL;DR). Anyway, it's great you added one more example of it with defined arguments.

As for the third argument, I believe I understand what was your problem. It's a pity, but as least it only affects one particular case (\$2=0) and this is well documented in the help file.