Variable changed without code

No comparison!

You are assigning 'not B' to A

A=!B

B == 0 == FALSE
!B == TRUE

A is assigned TRUE and the if always succeeds.

Try

A == !B

Or like tom said, the more intuitive version:

A != B