Example pitfall

From:
http://arduino.cc/en/Reference/FunctionDeclaration

int ReadSens_and_Condition(){
  int i;
  int sval;

  for (i = 0; i < 5; i++){
    sval = sval + analogRead(0);    // sensor on analog pin 0
  }

  sval = sval / 5;    // average
  sval = sval / 4;    // scale to 8 bits (0 - 255)
  sval = 255 - sval;  // invert output
  return sval;
}

“sval” is an uninitialised automatic.

Either:

int ReadSens_and_Condition(){
  int i;
  int sval;

  for (i = 0, sval = 0; i < 5; i++){

or

int ReadSens_and_Condition(){
  int i;
  int sval = 0;

  for (i = 0; i < 5; i++){

Fixed.

Thanks - should I delete this now?