gen~ codebox for loop

bertrandfraysse's icon

I'm trying to make a for loop with gen but don't know how to do...
but maybe there's another way to do than using a for loop...

here's what I try to do.

for example
if I input 3, I'd like the output to be (1*1) + (2*2)
if I input 4, I'd like the output to be (1*1) + (2*2) + (3*3)
if I input 5, I'd like the output to be (1*1) + (2*2) + (3*3) +(4*4)

I'm sure it's simple to do.
any idea ?

Thank you.

bertrandfraysse's icon
Max Patch
Copy patch and select New From Clipboard in Max.

I found this, but maybe there's a better way.

Wesley Smith's icon
Max Patch
Copy patch and select New From Clipboard in Max.

Here's another solution

bertrandfraysse's icon

nice, it's what I thought could be possible with for.
it's more efficient. (0.00028 cpu with my technique, 0.00017 cpu with yours)
thank you wesley,

Gennaro Schiano's icon

Thanks... was trying i++ for a couple hours haha +1 for += !