# LOOP SEQUENCE NUMBERS IN MAXSCRIPT

I have an array x = #(1,2,3...,n) . How can i create an array y :

y[1] = x[1]
y[2] = x[1] + x[2]
y[3] = x[1] + x[2] + x[3]
.................
y[n] = x[1] + x[2] + x[3] + .... +x[n]

Can you give me the funtion ? Thank you for your help

## Comment viewing options

### here..suppose it easy to make the fn yourself...

```eArr=#()
arr = #(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
for i=1 to arr.count do
(
local temp=#()
local txt= "y"+"["+(i as string)+"]="

if i == 1 then
(
txt+="x"+"["+(i as string)+"]"
)
else
(
for y=1 to i  do
(
txt+="x"+"["+(y as string)+"]"
if y==i do continue
txt+="+"
)
)

append temp #(txt)
join eArr temp
)

eArr

--#(#("y[1]=x[1]"), #("y[2]=x[1]+x[2]"), #("y[3]=x[1]+x[2]+x[3]"), #("y[4]=x[1]+x[2]+x[3]+x[4]"), #("y[5]=x[1]+x[2]+x[3]+x[4]+x[5]"), #("y[6]=x[1]+x[2]+x[3]+x[4]+x[5]+x[6]"), #("y[7]=x[1]+x[2]+x[3]+x[4]+x[5]+x[6]+x[7]"), #("y[8]=x[1]+x[2]+x[3]+x[4]+x[5]+x[6]+x[7]+x[8]"), #("y[9]=x[1]+x[2]+x[3]+x[4]+x[5]+x[6]+x[7]+x[8]+x[9]"), #("y[10]=x[1]+x[2]+x[3]+x[4]+x[5]+x[6]+x[7]+x[8]+x[9]+x[10]"))```

thats the formula... you could convert it to array of number (result) too with little tweak

### `

here u go

```fn NewArr a b:#() = (
for i = 1 to a.count do (
b[i] = 0
b[i] = for j = 1 to i collect b[i] += a[j]
)
b
)

a = #(1,2,3,4,5)
b = NewArr a

print b```