use millis() to measure time. Don't depend on a counter that will evolve at a speed proportional to the complexity of the code (and you never reset your counter as already reported). To measure a duration, you note the value of millis() when the start condition is met and then if the condition is still met, you compare the difference between the current millis() and the time you recorded to calculate the duration. that's what you compare.
To your question, you might benefit from studying state machines. Here is a small introduction to the topic: Yet another Finite State Machine introduction