For i = 2 To 20

Y(i) = X(i) + Y(i-1)

Next

Solved

Posted on 2011-10-27

I want to add numbers in arrays (20 each), in a trailing fashion. So, I think it is going to look like the following.

Y1=X1

Y2=X2

Y1=X1+X2 (OR Y1+X2)

Y3=X3

Y1=X1+X2+X3 (OR Y1+X3 OFCOURSE)

Y2=X2+X3 (OR Y2+X3)

So each Y will be addition of the 20 numbers. so Y(1) will be the addition of the numbers between X1-X20.

How can I construct the for loop for this?

thanks

Y1=X1

Y2=X2

Y1=X1+X2 (OR Y1+X2)

Y3=X3

Y1=X1+X2+X3 (OR Y1+X3 OFCOURSE)

Y2=X2+X3 (OR Y2+X3)

So each Y will be addition of the 20 numbers. so Y(1) will be the addition of the numbers between X1-X20.

How can I construct the for loop for this?

thanks

6 Comments

Each Y will be addition of 20 numbers

but there are a total of 5000 numbers.

Y1 will be the addition of X1-X20

Y2 will be the addition of X2-X21

..

Ylast will be the addition of X4980-X5000

```
For i = 1 To 4980
For j = 1 To 20
y(i) = y(i) + x(j + i - 1)
Next j
Next i
```

```
Y(1)=0
For i=1 To 20
Y(1)=Y(1)+X(i)
Next
For i=21 To 5000
Y(i-19)=Y(i-20)+X(i)-X(i-20)
Next
```

By clicking you are agreeing to Experts Exchange's Terms of Use.

A short article about a problem I had getting the GPS LocationListener working.

Join the community of 500,000 technology professionals and ask your questions.

Connect with top rated Experts

**19** Experts available now in Live!