Why is one part of my code being executed over the part before it?
The problem is with your logic. You are saying:


If it's too close in front then move backwards
Otherwise stop all movement
If it's too close on the left then move forwards
Otherwise stop all movement.


That means that if it's too close in front, but not too close on the left, then it will think about moving backwards, but then immediately stop because it's not too close on the left.

You need to think more about the whole space at once, not just one individual direction. For instance, what do you do if it's too close in front and too close on the left? At the moment you'll crash into whatever is in front.

So you should be thinking about four conditions:


Too close in front AND too close on the left
Too close in front BUT NOT too close on the left
NOT too close in front BUT too close on the left
NOT too close in front AND NOT too close on the left.


Then you can choose the right action to perform.

If your specific setup means that it can never be too close in front at the same time as being too close on the left you can collapse it into a simpler form:


IF it's too close in front then move backwards
ELSE IF it's too close on the left then move forwards
ELSE stop all movement.