Superku, of course your approach is working, but it's not a good style from my point of view as it introduces new dependencies. Whenever you change the limit of the loops you have to remember that you have to adapt the inner assignment as well. That is likely to be forgotten.

I'd introduce a new function, extract the three nested loops to this function and use a return instead of the break.


Always learn from history, to be sure you make the same mistakes again...