Hmmm... got a bit of a hiccup there. Must be using Internet Explorer.
My comment regarding the state machine still holds for your primary question.
For you second question, can you show us the code? Your description about an outer while loop and pressing a button don't really provide enough to be able to understand what the code is doing.