There are many examples on this WEB site that will help with understanding a State Machine.
Here is just one example that should help in your journey.