Reseting a routine from within itself

Hi! I need to have a routine that can embed a pattern and then embed another pattern when the previous pattern ends.

~pattern = Pseq([1, 2, 3, 4],1);
~pattern = Pseq([5, 6, 7, 8], 1);

r = Routine {

This “works” but it’s obviously not the greatest solution. I want to have the routine reset somehow when the pattern ends so that I can redefine the variable ~pattern when ever and have it embeded on time.

The only way i can find to reset a routine from within itself is the .yieldAndReturn method but as the name suggests it also yields something so it’s not very useful to me.

Ok i solved with this hacky function:

var next;;
if (next==nil, {}, {next});

Keeping the thread open though. More elegant solutions are welcome.

Oh wow that was easy. thank you!

Your welcome.

SC comes with a heavy doc source… you might check out this as well:

Anything else, feel free.

Yeah I’ve gone through that doc a few times. loop slipped by unnoticed somehow.