Run a program for a specific amount of time

//Left & Middle & Right = White
//Move Forward
if((analog(2)>CR)&&(analog(1)>CR)&&(analog(0)>CR)){
motor(1,75);
motor(2,75);
motor(3,75);
motor(4,75);
}
I wanna run this program for a specific amount of time without affecting my other statement I tried to used delay but it affects other statements. Is there anyway I can time on how long a program will last and it will continue all other if statements if it already finished?

Look at the blink without delay example in the IDE (File, Examples, Digital) and this post. That will show how to do non-blocking timing.

Please read the "how to use the forum" stickies to see how to properly format and post your code. We also request that you post the whole sketch.

see Several Things at a Time

So this is the program I want to implement it with. This is for line following.

#include <ATX2.h>
#include <ATX2_gp2d120_lib.h>
int CR=500,CL=450;
void setup()
{
  OK();// Wait for OK button
  delay(2000);
}
//motor4=Right Front
//motor3=Right Back
//motor2=Left Front
//motor1=Left Back
void loop()
{
//IR Left + Left & Middle & Right = Black
//Turn Left
if((analog(7)>110)&&(analog(2)<CR)&&(analog(1)<CR)&&(analog(0)<CR)){
    motor(1,-35);
    motor(2,-35);
    motor(3,50);
    motor(4,75);
 }
 
//Bumper Switch Front
//If wall is hit Forward for 1.5 sec,Backward for 1 sec,Spin 180,Forward for 0.8 sec
if(analog(5)<1){
    fd4(25);
    delay(1500);
    bk4(50);
    delay(1000);
    sr4(50);
    delay(1900);
    fd4(50);
    delay(800);
 }

//IR Front + Left = White + Middle & Right = Black
//Move Forward for 0.5 sec
if((analog(3)>40)&&(analog(2)>CR)&&(analog(1)<CR)&&(analog(0)<CR)){
    motor(1,50);
    motor(2,50);
    motor(3,50);
    motor(4,50);
    delay(500);
 }

//Left & Middle = Black + Right = White
if((analog(2)<CR)&&(analog(1)<CR)&&(analog(0)>CR)){
    motor(1,50);
    motor(2,75);
    motor(3,-35);
    motor(4,-35);
 }
 
//Left & Middle = White + Right = Black
else if((analog(2)>CR)&&(analog(1)>CR)&&(analog(0)<CR)){
    motor(1,-50);
    motor(2,-50);
    motor(3,50);
    motor(4,100);
 }

//Left & Middle & Right = White
else if((analog(2)>CR)&&(analog(1)>CR)&&(analog(0)>CR)){
    motor(1,75);
    motor(2,75);
    motor(3,75);
    motor(4,75);
 }

//Left = White + Middle & Right = Black
else if((analog(2)>CR)&&(analog(1)<CR)&&(analog(0)<CR)){
    motor(1,-35);
    motor(2,-35);
    motor(3,50);
    motor(4,75);
 }
 
 //Left & Right = White + Middle = Black
else if((analog(2)>CR)&&(analog(1)<CR)&&(analog(0)>CR)){
    motor(1,75);
    motor(2,75);
    motor(3,75);
    motor(4,75);
 }
 
 //Left & Right = Black + Middle = White
else if((analog(2)<CR)&&(analog(1)>CR)&&(analog(0)<CR)){
    motor(1,75);
    motor(2,75);
    motor(3,75);
    motor(4,75);
 }
 
 //Left = Black + Middle & Right = White
else if((analog(2)<CR)&&(analog(1)>CR)&&(analog(0)>CR)){
    motor(1,50);
    motor(2,100);
    motor(3,-50);
    motor(4,-50);
 }
 
 //Left & Middle & Right = Black
else if((analog(2)<CR)&&(analog(1)<CR)&&(analog(0)<CR)){
   motor(1,50);
   motor(2,50);
   motor(3,50);
   motor(4,50);
 }
}

Good see answer #1 and #2 for ideas on how to do that (you'll probably need a state machine)