A Problem with an While Control Structure

Hey dear love Community,
I have a little bit Problems with a Function that I have written.

This is may Function:
( ~findParameter = {
arg list;
var lets, num, numus, ii;
num = list.size;
numus = 0;
for (0, num, { arg i; if( list.at(i)!=nil, {numus = numus + 1})});
numus = numus.rand-1;
lets = if ( numus > 0, {
ii = -1;
while(numus > 0, {
ii = ii +1;
if( list.at(ii)!=nil, {numus = numus - 1});
});
list.at(ii-1)}
,{ [1,1,1] });
[lets[1], lets[2]].choose;
})

which I have tested as Example with:

~findParameter.value([Nil, [1,2,3], Nil]);

The Problem seams to be the “While” in this Code.
I have tested and trying all, but it gives three Actions the Script will do when run:

  1. I became the Standard Answer 1 see the If Structure

  2. It crashed it explains the While Condition will not Change.

Can anybody give me a hint what I do here Wrong

In hope of Hints

CreCo
Thomas Lahme

http://doc.sccode.org/Reference/Control-Structures.html#.while

while ( testFunc, bodyFunc );

While takes a test function. That’s a function, not a free-standing expression.

You’ll need the test to evaluate once per loop cycle.

In SuperCollider, the only way to write something that will be evaluated multiple times is to write it as a function: while { numus > 0 } { loop body... }.

This is different from Java and C. It’s a fairly common question – quite often, SC users assume that control structure syntax will match what they know from C. But SC control structures are really only method calls (with some compiler optimizations), so the Java/C rules don’t apply.

hjh

Thank you

thats helps me

CreCo
Thomas Lahme