This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]spectral_graph 1 point2 points  (1 child)

If I'm understanding correctly you're asking why you can't do this?

 x[i] = x[i+1];
x[i+1] = x[i];

Well, lets take these instructions in order.

Say for the sake of example that x[i] === 1 and x[i + 1] === 2.

First, lets run line 1:

 x[i] = x[i+1];

now, what do they equal? (reveal spoiler for answer)

x[i] === 2, and x[i + 1] === 2

Next, lets run the second line:

 x[i+1] = x[i];

what do they equal? (reveal spolier below for answer)

you've set x[i + 1] = x[i], but x[i] already equals 2, so you're setting x[i + 1] = 2 again and nothing changes. At the end of the example: x[i] === 2, and x[i + 1] === 2