program for infrared sensore

Design–>i have made a robot which has got two motors at the back and one castor wheel on the front end nd I have attached two infra red sensors on the front .
My aim is to move my robot on a surface without the robot falling off the surface.That is the reason i have used infra red sensors as it will detect where the surface is ending and will turn accordingly so that it doesnt fall off the surface.Also i want my robot to follow the below path

So, where is you code? You can't program the infrared sensor. It's too dumb. All you can do is read it.

I know i cant program the code for ir sensor but i want to write the program for arduino board that will controll it

What code do you have? Do you have code to make the robot move? Do you have code to make the robot read the sensors? Do you have code to make the robot turn 90 degrees? How does the robot know when it has completed a 90 degree turn?

int sFL, sFR;
void setup() {

Serial.begin(9600);

pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
}

void loop()
{sFL = analogRead(A0);
sFR = analogRead(A1);
if ( sFL>0 && sFR>0 )
{
digitalWrite (2,LOW);
analogWrite (3,70);
digitalWrite (4,LOW);
analogWrite (5,90);
}
else if (sFL==0 && sFR)
{digitalWrite (2,LOW);
analogWrite (3,0);
digitalWrite (4,LOW);
analogWrite (5,0);
delay(2000);

digitalWrite (2,LOW);
analogWrite (3,70);
digitalWrite (4,HIGH);
analogWrite (5,190);
delay(875);

digitalWrite (2,LOW);
analogWrite (3,50);
digitalWrite (4,LOW);
analogWrite (5,70);
delay(500); //90 degree complete now

digitalWrite (2,LOW);
analogWrite (3,70);
digitalWrite (4,HIGH);
analogWrite (5,190);
delay(875);
}
}

The above code makes the robot move in a rectangular shape (refer to the image below) which i dont want I want to move it the way i have shown in the pic…

You need to create some functions, like moveForward(), turnRight(), turnLeft(), etc. Move the code from loop() that causes the robot to move forward to moveForward(). Move the code that makes the robot turn to the appropriate function. Then, call the functions in place of the code you moved out.

Once you can tell the robot to turnRight(), moveForward(), etc. it becomes much simpler to move in any desired path.

But how can we do that? Please give me the coding.?Also i thought of creating 2 loops that is the first loop would go forward and then right and the 2nd loop would turn left and then move forward.But the thing is how can i program it to work alternatively that is the 1st loop should be executed the first,then the second and then again the first and so on..