handled fsm control flow using a while stmt