If and While are two completely different things. Your code says "If" hit is true. That condition is only evaluated at the top of the code section. At the end, program execution carries on regardless, because no further checking is done.
So you are leaving that section. I presume you have some kind of loop which is constantly running this section of code. As soon as you go past the EndIf, you're out of scope.
So you are leaving that section. I presume you have some kind of loop which is constantly running this section of code. As soon as you go past the EndIf, you're out of scope.