I understand about the WHILE - I should have checked both variables, but I got (get) very confused by meaningless single character variable names. Presumably n represents something that could be expressed in a meaningful name? And the variable i also?
You did not deal with the other (more important) points in my Reply #17
...R