Okay, first things first, put your code IN CODE TAGS. Quote tags are for quotes, code tags are for code. They work exactly the same way, except instead of putting the word "quote" between a set of [ ], you put the word "code" (without " " of course). Code tags have the wonderful benefit of maintaining your indentation, thus keeping me from wanting to rip my eyes from my socket.

As for the flag, once it gets set to 1, it wont magically go back to 0. You have to set that yourself somewhere, probably right after you finish acting on it. In your case, that may be once you check it and break out of your loop accordingly.