I'm sorry, i'm new, i don't understand what a 'state machine' means.
Also, can you be a little more explicit about how to 'execute the code for the current state'.
From my part i'm asking myself if i have to make a breakable loop into the function or if i must restructure the main program.
Thanks.