Comparing variables from one loop to the next

I'm trying to compare the value of a variable from the previous loop to the value in the current loop. Clearly, it's not working, I'm not sure what I'm doing wrong.

The variable in question is 'lastVal', the value is assigned by analogRead(0). In the if/else statement, the sketch only ever performs the 'else' portion:

int x; 
int led = 13;

void setup()
{
  Serial.begin(9600);
  pinMode(led, OUTPUT);
}

void loop() 
{
  int lastVal;
  x = analogRead(0);
  if (x < lastVal)
  {
    digitalWrite(led, HIGH);
    Serial.print("x: ");
    Serial.print(x, DEC);
    Serial.println(". Light On.");
  }
  else
  {
    digitalWrite(led, LOW);
    Serial.print("x: ");
    Serial.println(x, DEC);
  }
  x = lastVal;
  delay(100);
}

Your help is greatly appreciated.

int x;
int lastVal = 0; //set initial value to 0
int led = 13;

void setup()
{
  Serial.begin(9600);
  pinMode(led, OUTPUT);
}

void loop()
{
  x = analogRead(0);
  if (x < lastVal)
  {
    digitalWrite(led, HIGH);
    Serial.print("x: ");
    Serial.print(x, DEC);
    Serial.println(". Light On.");
  }
  else
  {
    digitalWrite(led, LOW);
    Serial.print("x: ");
    Serial.println(x, DEC);
  }
  lastVal = x; // 'save' the value of x to next iteration
  delay(100);
}

Not tested. :]

Brilliant! That worked just fine.

Thank you very much AlphaBeta

I knew it had to be something simple, but you stare at something long enough, and it all starts to blur together.