if else loop issues

Try this (and see my comments):

int sensor = 0;
int ledPin = 5;

int val2;

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

}

void loop(){
  int val = analogRead(sensor);
  Serial.println(val);
  delay(100);
  if (val<1020) {
    digitalWrite(ledPin, HIGH);
  }
  else {
    digitalWrite(ledPin, LOW);
  }


  if (val>1020){
    val2=0;
  }

  else if (1000<val){ // will only reach here if val <= 1020 so no need to test
    val2=1;
  }

  else if (910<=val){ // will only reach here if val <= 1000 so no need to test
    val2=2;
  }
  else if (898<val){ // will only reach here if val < 910 so no need to test
    val2=3;
  }
  else if (810<=val){ // will only reach here if val <= 898 so no need to test
    val2=4;
  }
  else if (800<val){ // will only reach here if val < 810 so no need to test
    val2=5;
  }
  else if(740<val){ // will only reach here if val <= 800 so no need to test
    val2=6;
  }
  else { // will only reach here if val <= 740
    val2=7;
  }
} // Don't forget the closing brace for loop()...

Also, if ... else isn't a loop, it's a conditional control structure. Please watch your terminology to keep confusion down.