Table isn't working the way I thought it would

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By scooty
var P1 = 5
var P2 = 10
var P3 = 15
var Points
Points = [P1, P2, P3]
for i in Points:
       i = 0
print(Points[0]

That’s my code
It prints 5. Why can’t I change a value in a table?

:bust_in_silhouette: Reply From: spaceyjase

The for loop i is a copy of each element in the array, the same way this doesn’t change P1:

var P1 = 5
var P2 = P1
P2 = 0
print(P1) # 5

If you want to change an array element, you need to loop using a index:

for i in Points.size():
    Points[i] = 0
print(Points[0]) # zero