Loop the loop problem

Question

Hints

Answer