Your code overwrites y[10], which does not exist. It is not part of the array; it is whatever happens to be next to the array. If the value j is being stored there, you'd be overwriting j with 2 and that would make it loop forever.
Don't write into array elements that don't exist. It's very bad.