Serial Monitor statements

Ok, sorry for the ugly code. I'll keep that in mind...

The plan was:
1st: read the analog value
2nd: store the analog value in the variable "prevState"
(the delay was set here to make shure i don't get the same result from the sensor twice... )
3rd: read the analog value again and compare it with the "prevSate"

It seems to work (still not solved: the "double" UPs and DOWNs).

So in this version i need two int variables, sensorValue and prevState to do the job.
But maybe i haven't quite understood the concept. Am i totally wrong?
Regards, Christopher

/*
AnalogRead IR 02.12.2012
 */

int prevState = 0;

void setup() {
  Serial.begin(9600);
}

void loop() {
  int sensorValue = analogRead(A0);

  prevState = sensorValue;

  delay (1);
  sensorValue = analogRead(A0);

  if (sensorValue>500 && prevState<500)
  {
    Serial.println("UP");
  }
  if (sensorValue<500 && prevState>500)
  {
    Serial.println("DOWN");
  }
}