variable in for loop changes by itself
I'm trying to replicate the behavior in excel where you can add a blank line to a spreadsheet. I have a form looking like a spreadsheet where I named my fields according to their line number. I have a single field where the user inputs the line number where he wants a line to be added and a button to trigger the action. I created a script that is composed of 2 For Loops inside one another. The first loop goes through the lines while the second one goes through each individual field of a line. The goal is to take each value starting from the second to last line and move it to the same field, on the next line. Value of variable line is 3. Here is what I came up with:

I inserted a bunch of println to see what was wrong with my code. Notice that only the first 3 lines are filled so I pasted only the console refering to those lines. For some reason, as soon as there is a value inside a cell, the variable i switches to 0. Here is the result:
myData is
NATURE.3 pasted
CI.3 copied
myData is
CI.3 pasted
i is 2
TIME.CALL.2 copied
myData is
TIME.CALL.2 pasted
TIME.1018.2 copied //This is the stange part. As soon as I hit a value, i switches to 0 when it should stop at 2 since the value of line is 3
myData is 0900 //myData shows the correct value
TIME.1018.0 0900 pasted //TIME.1018.0 should be TIME.1018.2 althought the correct value is pasted to the correct field (strangely)
TIME.END.0 copied //i switched to 0, skipping 1 in the loop althought it should not even be less than 2
myData is 0730
TypeError: this.getField("OPE004.RAQ." + aFields
29:Field:Mouse Up
