Remembering button state

int lastState; // define outside to keep its value

Or define it "static" inside loop:

void loop()
{
  static int laststate = LOW;
  int currentstate = digitalRead(somePin)

  if(currentstate != laststate)
  {
    laststate = currentstate;
    // do something
  }
}