< Back to IRCAM Forum

Recursive operations in a loop

Dear all,

This should be a trivial problem, but I simply cannot figure it out. I’ve tried all sorts of things, but to no avail.

Essentially, I’ll have an arbitrarily long list of numbers. What I want to do is for each number in the set, check to see if it is < 10000. If it is < 10000 then + 1000 until > than. Otherwise return the original value.

I can’t seem to figure out how to do this - it’s driving me mad! I’ve tried all sorts of embedded loops, different accumulators, etc. Perhaps my thinking is too influenced by ‘C-like’ languages and I’m missing something.

Best,
Nigel

Hi Nigel,

see the attachment. I think all you need is a loop inside another loop.
by using the “for” iterator you can accomplish the task

If it works as you want it you can collect the data and get them as a list

best
dimitris maronidis

patch.omp (19 KB)

Hi Nigel. Another way could be using the variou modulo-type functions - round, floor, mod, rem - to fit the number within a range. ie.

(+ 10000 (rem number 1000))

would place number above 10000 according to the modulo (1000)

ive included a patch using mapcar and the principle above to fit numbers.

fit-above.omp (3.8 KB)