Question: I'm trying to increment an index in a loop for but my program does not work. I have a simple array with 10 elements and I want to sum all elements of this array. I'm having problem, because I consider two loop, first I want to calculate the five first elements and than the five last, but my counter i\_i does not change in the program, the code is

```
import numpy as np
from matplotlib.pylab import *

x = [1, 2, 3, 4, 5, 6, 7, 8 ,9 ,10]

i_i = 0
i_j = 5
sum_t = 0.0

for i in range(2):
    for ii in range(i_j):
        sum_t += x[i]
    i_i += 5
    i_j += 5

print(sum_t)

```

The valeu of the sum must be 55, but I'm have problem with the index i\_i. Any suggestion is welcome to make the program work in this way.

Answer: 
You used the wrong variable in the second loop, it is `ii`, not `i`. Secondly the last loop must go from `i_i` to `i_j` so your range is also wrong:

```
import numpy as np
from matplotlib.pylab import *

x = [1, 2, 3, 4, 5, 6, 7, 8 ,9 ,10]

i_i = 0
i_j = 5
sum_t = 0.0

for i in range(2):
    for ii in range(i_i, i_j):
        sum_t += x[ii]
    i_i += 5
    i_j += 5

print(sum_t)

```
You forgot to use the i\_i index and in the second for you were using i instead of ii.

```py
x = [1, 2, 3, 4, 5, 6, 7, 8 ,9 ,10]

i_i = 0
i_j = 5
sum_t = 0.0

for i in range(2):
    for ii in range(i_i, i_j):
        sum_t += x[ii]
    i_i += 5
    i_j += 5
    print (i_j)

print(sum_t)

```

But I would just use this:

```
print(sum(x))

```