i took the variables out
i had to keep j isolated
Why? That shows the problem with the posted code. The code must not be following the algorithm. The code as posted will not work.
What will the value of j be when the for loop ends?