Hello again, sorry for posting so many questions, but I’m in full develop mode right now
I’m trying to figure out how to remove indexes from a List only if there are any left to remove. I tried to write this:
h = List.fill(10,{arg i; i});
(
Routine {
if(h.notEmpty,{
inf.do({arg i;
h.remove(h.choose);
i.postln();
if(h.isEmpty,{postln("empty");});
1.wait;
});
});
}.reset.play;
)
or this:
h = List.fill(10,{arg i; i});
(
Routine {
if(h.isEmpty,{}, {
inf.do({arg i;
h.remove(h.choose);
i.postln();
if(h.isEmpty,{postln("empty");});
1.wait;
});
});
}.reset.play;
)
you can see that the inf.do
loop is till going on because on the post window i.postln();
keep posting arg i
even if h.isEmpty = true
or in the other case h.notEmpty = false
.
What I’m doing wrong here? Thank you
Add on
I tried this:
h = List.fill(10,{arg i; i});
(
Routine {
if(h.size != 0,{
20.do({arg i;
h.remove(h.choose);
i.postln();
//if(h.isEmpty,{postln("empty");});
0.2.wait;
});
});
}.reset.play;
)
and it seems that even if h.size != 0
or h.isEmpty = true
or h.notEmpty = false
, it still keep to run the .do
function until it’s over (and in the case of inf.do
it never ends).
Also tried this:
h = List.fill(10,{arg i; i});
(
r = Routine{
20.do({arg i;
h.remove(h.choose);
i.postln();
if(h.isEmpty,{postln("empty");});
0.2.wait;
});
};
Routine {
if(h.notEmpty,{
r.reset.play;
}, {
r.stop;
});
}.reset.play;
)