Controlling servo with IR led and photodiode

I think that I have come to a dead end at this project so any help would be appreciated. I’ve done this two projects individually and they work but I just can’t put them together, something is always going wrong. My senzor is 100% accurate when his job to simply turning on and off LED diode and servo is sweeping 90 degrees back and forth like it should be but since I have to make a pretty big code im completely sure problem is in it. Principle is this: when there is something in between IR led and photodiode servo goes 90 degrees and then that “someting” disappears from range servo goes back to 0 position. When nothing is in range servo simply stays in 0 position. Tnx

   #include <Servo.h>
Servo myservo;

int senRead = 0;                 
int limit = 850;                 
int photodiode = 2;               
int pos = 0;                     

void setup()
{
  myservo.attach(9);  
  digitalWrite(photodiode, HIGH);  
  Serial.begin(9600);             
}
void loop()
{
  int value = analogRead(senRead); 
  Serial.println(value);          
  if (value > limit)              
  {
    for (pos = 0; pos <= 90; pos += 1)
    {
      myservo.write(pos);              
      delay(25);
      delay(2000);
    }
    if (value < limit)

      for (pos = 90; pos >= 0; pos -= 1)
      {
        myservo.write(pos);             
        delay(25);  
        delay(2000);
      }
  }
  if (value < limit)
  {
    myservo.write(0);
    delay(2000);
  }
}
 for (pos = 0; pos <= 90; pos += 1)
    {
      myservo.write(pos);             
      delay(25);
      delay(2000);
    }

That will take about 3 minutes to move from 0 to 90 degrees. Did you mean that?

Does this work better (compiles, but untested)?

#include <Servo.h>
Servo myservo;

int senRead = 0;
int limit = 850;
int photodiode = 2;
int pos = 0;

void setup()
{  
  myservo.attach(9);
  digitalWrite(photodiode, HIGH);
  Serial.begin(9600);
}
void loop()
{
  int value = analogRead(senRead);
  Serial.println(value);
  if (value >= limit)
  {
    for (pos = 0; pos <= 90; pos += 1)
    {
      myservo.write(pos);
      delay(25);
    }
    while (value >= limit)  //wait and watch sensor for off condition
    {
      value = analogRead(senRead);
    }
    for (pos = 90; pos >= 0; pos -= 1)
    {
      myservo.write(pos);
      delay(25);
    }
  }
   else
  {
    myservo.write(0);
    delay(2000);
  }
}

Look at the "blink without delay" example in the IDE examples (File, Examples, Digital) and this post to see how to do non blocking timing. Basically, record the time, using millis(), when you start waiting and, periodically, check the difference between the recorded time and the current millis() to see if the time has elapsed.

I don't understand it: code in first post is strange but it should work. Slowly but should work. Where is the mistake?