Code sequencing issue

aimes32:

if (lightleft - lightright > 30)


                rot_ccw (500, 75);      // rotate clock-wise for 500 mS at speed 75
              }
             
              else if (lightright - lightleft > 30)
              { 
                 rot_cw (500, 75);      // rotate clock-wise for 500 mS at speed 75
              }
             
             
              else if (distanceLeft < 35)
              {             
                  reverse(500, 75);        // reverse for 500 at 75
                  rot_cw (500,75);          // rotate clockwise for 500 at 75
              }
             
              else if (distanceRight < 35)
              { 
                 reverse (500,75);        // reverse for 500ms at 75
                 rot_ccw (500,75);        // rotate countercloackwise for 500ms at 75
              }
             
              else if (distanceLeft < 35 and distanceRight < 35)
              {
                reverse (500, 75);      // reverse for 500ms at speed 75
              }
               
              else
              {
                forward (200, 75);     // move forward for 200ms (2000 ms) at speed 75 (75/255ths of full speed)
              }           
             
             
}



should be executed if it is removed.

Actually this will be executed even if it isn't removed, right?

              if (lightleft - lightright > 30)
              {  
                rot_ccw (500, 75);      // rotate clock-wise for 500 mS at speed 75
              }
              
              else if (lightright - lightleft > 30)
              {  
                 rot_cw (500, 75);      // rotate clock-wise for 500 mS at speed 75
              }

So the problem code is after the code that you removed, not before it. We presume we are not doing those two things, otherwise it would never reach the code you removed. So the following is what is causing your problems, shouldn't be too hard to find:

 else if (distanceLeft < 35)
  {              
    reverse(500, 75);        // reverse for 500 at 75
    rot_cw (500,75);          // rotate clockwise for 500 at 75
  }

  else if (distanceRight < 35)
  {  
    reverse (500,75);        // reverse for 500 at 75
    rot_ccw (500,75);        // rotate countercloackwise for 500 at 75
  }

  else 
  {
    forward (200, 75);     // move forward for half a second (2000 ms) at speed 75 (75/255ths of full speed)
  }