State Machines

This compiles:

enum states { STATE_1, STATE_2, STATE_3, STATE_4, STATE_5, STATE_6, MAX_STATES };

states state;

void setup ()
  {
  
  }  // end of setup

void loop ()
  {
  switch (state)
    {

    case STATE_1 : 
      // if this does that, do something
  
      state = STATE_2;
      break;
  
    case STATE_2: 
      // if this does that, do something
  
      state = STATE_3;
      break;
    }  // end of switch 

  }  // end of loop