How to break several nested 'for' loop in one 'if'