Craft entries statements failing
I'm not 100% following your question, but it's likely a variable re-use issue.

Basically, you're setting the variable once, and if it exists, do blah....

Then, you're attempting to re-set that variable below.  Something goes wrong with that, but entry still exists at that point, so it passes the seconds test but in that second block  entry is still pointing to the data it retrieved in the first use.

(You might find it useful to check out:
https://straightupcraft.com/articles/testing-if-something-exists-is-defined-length-is-not-null-is-not-empty

...which has a whole lot of stuff about testing variables too)