Firstly you don't don't have a 3rd nested loop it's a for statement inside nested loop, just so you realise :P.

Secondly you just need a statement to prevent it from running when it's comparing...