2 ir sensors line follower code

Hi all,
i am in urgent need to improve this code to stop at the 17th black line ,so i need to know how to write a counter that can count black lines and stop at end which is the 17th black line.
thanks in advance.

/*------ Line Follower ---- */
/*-------definning Inputs------*/

#define LS 2         // left sensor
#define RS 3        // right sensor

/*-------definning Outputs------*/
#define LM1 4       // left motor
#define LM2 5       // left motor
#define RM1 6       // right motor
#define RM2 7       // right motor

void setup()
{
pinMode(LS, INPUT);
pinMode(RS, INPUT);
pinMode(LM1, OUTPUT);
pinMode(LM2, OUTPUT);
pinMode(RM1, OUTPUT);
pinMode(RM2, OUTPUT);
}

void loop()
{
if(digitalRead(LS) && digitalRead(RS))        // Move Forward
{
 digitalWrite(LM1, HIGH);
 digitalWrite(LM2, LOW);
 digitalWrite(RM1, HIGH);
 digitalWrite(RM2, LOW);
}

if(!(digitalRead(LS)) && digitalRead(RS))     // Turn right
{
 digitalWrite(LM1, LOW);
 digitalWrite(LM2, LOW);
 digitalWrite(RM1, HIGH);
 digitalWrite(RM2, LOW);
}

if(digitalRead(LS) && !(digitalRead(RS)))     // turn left
{
 digitalWrite(LM1, HIGH);
 digitalWrite(LM2, LOW);
 digitalWrite(RM1, LOW);
 digitalWrite(RM2, LOW);
}

if(!(digitalRead(LS)) && !(digitalRead(RS)))     // I need to make counter here to stop after 17th condition
{
 digitalWrite(LM1, HIGH);
 digitalWrite(LM2, LOW);
 digitalWrite(RM1, HIGH);
 digitalWrite(RM2, LOW);
}
}

You need to see the state change example in the IDE.

You also need to use code tags when posting code.

You do not need to read the pins 4 times, to make 4 decisions. Learn about else if statements, too.

above code does not work please help me