A loop to filter a list of numbers into a new list but how to in Max?
I am new to Max, but not to programming in other languages like Java. I am also following the tutorials and reading some books, but I still cannot figure out how I should do the following:
I want to create a while loop (in Java terms) to loop over a list with numbers in it. Inside this loop, I want to determine, with "if" for example, whether a certain number from the list passes the conditions or not. So I want to loop over all the numbers in the list, and all the numbers that pass should be gathered in another list. The numbers that do not pass the conditions can be thrown away.
I would know how to do this in Java, but in Max I find this difficult. I am also not sure about which objects I should use. Select? If? Uzi? A counter?
All tips are welcome!
uzi and counter are one of many solutions.
generally you should try to avoid recreating a loop where possible.
the [zl] object(s) for example do a lot of jobs to lists, and when the condition you want to check against can be solved arithmetically you might want to build it around [vexpr].
if it is a really complex job - and recursive - you can also move it into a [poly~] object, which lets you process an algorithm also serial (its main purpose is probably parallel processing.)
last but not least, and with some not-so-obvious tricks, you can also use private or global variables ([v], [pvar]) in max, which you would nee to retrigger in order to build a loop.
and, i dont know them at all, but the third party ool ("object orientated") objects might also perform this.
attached is a very, very oldschool solution.
save as [110.iterate-insert] and
replace [110.defarg] with [if $f1!=0. then $f1 else $f2.]
then you connect it like this: [110.iterate-insert] X[youralgo]
-110
@DOUBLEUG Thank you! I understand what your patch is doing and it is really useful for what I try to achieve.
@ROMAN THILENIUS Thank you too. I have to admit that I do not really understand your patch. And why should loops be avoided?