You should use the debugger to see what is going on. Maybe you are leaving your code at an unexpected point, like the two breaks at first.
I dont know whether your must trigger the execution from outside when flipping the if.
Why arent you control the loop with
while( !(code1 & code2))