To further on that. Your probably changing the value of y1 to something greater than the maximum dimension of the array. Because in a FOR/NEXT the condition is evaluated at the beginning of the loop and follows through, any changes you make to the FOR/NEXT variable won't be looked at, at the end of the loop.
Use a REPEAT/UNTIL loop if you wish it to happen that way.
Use a REPEAT/UNTIL loop if you wish it to happen that way.