If statement in switch case

Hey guys,

I am trying to get a robot to go through different situations, depending on how many times the sensor reads a wall. If we just have the switch statements without the if embedded, the switch case will run through its cases. But when we put a if statement that should read if a wall is detected, the distance sensor does not work anymore… what is the problem?

Here is the code:

// motor one
int LeftMotorSpeed = 10;
int LeftMotorFwd = 9;
int LeftMotorRvs = 8;

int distancesensor = 0;
int dist = 0;
int object = 600;

int i = 1;

void setup() {
// put your setup code here, to run once:
dist = analogRead(distancesensor);
// set all the motor control pins to outputs
pinMode(LeftMotorSpeed, OUTPUT);
pinMode(LeftMotorFwd, OUTPUT);
pinMode(LeftMotorRvs, OUTPUT);

}

void loop() {
// put your main code here, to run repeatedly:
switch (i){
case 1:

if (dist < object){

//Motor one stop
digitalWrite(LeftMotorFwd, HIGH);
digitalWrite(LeftMotorRvs, LOW);
analogWrite(LeftMotorSpeed, 255);
delay(2000);
i++;
}

else (dist >= object){
//Motor one stop
digitalWrite(LeftMotorFwd, LOW);
digitalWrite(LeftMotorRvs, LOW);
analogWrite(LeftMotorSpeed, 255);
delay(2000);
i++;
}
break;

case 2:

//Motor one stop
digitalWrite(LeftMotorFwd, LOW);
digitalWrite(LeftMotorRvs, LOW);
analogWrite(LeftMotorSpeed, 255);
delay(2000);
i++;
break;

case 3:

//Motor1 forward at full speed
digitalWrite(LeftMotorFwd, LOW);
digitalWrite(LeftMotorRvs, HIGH);
analogWrite(LeftMotorSpeed, 255);

delay(2000);
i++;
break;
}

}

      else (dist >= object)Would this be better as       else if (dist >= object)I wonder ...

And this is expected to do.... what??

else (dist >= object){

Regards, Ray L.

if (dist < object){

Why do you only read the distance once?
What are all those delays doing in there?

(BTW, see what I did with code tags there? You could have done that too)