Arduino output states
You need to keep track of your direction with a variable.

Pseudo code.

void setup{
  dir = 0;                    //Default move left.
}

void loop{
  if (!dir &amp;&amp; leftSense) {    //Moving left and left sensor turns on ...
    dir = 1;                  //... move right
  }
  if (dir &amp;&amp; rightSense) {    //Moving right and right sensor turns on
    dir = 0;                  //... move left
  }
  // Other stuff
}