Problems with multiple if statements

I am having an issue with my servos not responding to my inputs. I ran the code without the “if” statements and the servos and it worked how i intended it to. I am just running my I/O for my infrared sensors to a bread board and manually completing the circuit. I believe the problem is my “if” statements. Is there a way i could simplify the statements into one to be less confusing? Thanks in advance

#include <Servo.h>
int pos1 = 0; //X axis motor position
int pos2 = 10; //Y axis motor position
Servo myservo1; //X axis motor
Servo myservo2; // Y axis motor
int PIR1 = 23; //Power to Infrared 1
int PIR2 = 25;
int PIR3 = 27;
int PIR4 = 29;
int IIR1 = 22; //Input from Infrared 1
int IIR2 = 24;
int IIR3 = 26;
int IIR4 = 28;
void setup() {
  pinMode(IIR1, INPUT);
  pinMode(IIR2, INPUT);
  pinMode(IIR3, INPUT);
  pinMode(IIR4, INPUT);
  pinMode(PIR1, OUTPUT);
  pinMode(PIR2, OUTPUT);
  pinMode(PIR3, OUTPUT);
  pinMode(PIR4, OUTPUT);
  myservo1.attach(9);
  myservo2.attach(10);
  digitalWrite(PIR1, HIGH);
}

void loop() {
  if (digitalRead(IIR1) == HIGH) {
    for (pos2 = 10; pos2 <= 80; pos2 += 1) { // Head slowly rises
      myservo2.write(pos2);
      delay(30);
    }
  }
  if (pos2 == 80) {
    digitalWrite(PIR1, LOW); // Turn off power to IR 1
    digitalWrite(PIR2, HIGH);
    myservo1.write(25);
  } //Move Head to far right
  //

  if (digitalRead(IIR2) == HIGH){
    for (pos1 = 25; pos1 <= 60; pos1 += 1) { // Move head towards sensor 2
      myservo1.write(pos1);
      delay(30);}
    }
  if (pos1 == 60) {
    digitalWrite(PIR2, LOW);//Turn off Power to IR 2
    digitalWrite(PIR3, HIGH);
  }
  if (digitalRead(IIR3) == HIGH)
    for (pos1 = 60; pos1 <= 85; pos1 += 1) { // Turn Head to IR3
      myservo1.write(pos1);
      delay(30);
    }
  if (pos1 == 85) {
    digitalWrite(PIR3, LOW); //Turn off Power to IR3
    digitalWrite(PIR4, HIGH);
  }
  if (digitalRead(IIR4) == HIGH)
    for (pos1 = 85; pos1 <= 120; pos1 += 1) {
      myservo1.write(pos1);
      delay(30);

    }
  if (pos1 == 120) {
    myservo2.write(10);
    myservo1.write(60);
    digitalWrite(PIR4, LOW);
    digitalWrite(PIR1, HIGH);
  }
}
 #include <Servo.h>
int pos1 = 0; //X axis motor position
int pos2 = 10; //Y axis motor position
Servo myservo1; //X axis motor
Servo myservo2; // Y axis motor
int PIR1 = 23; //Power to Infrared 1
int PIR2 = 25;
int PIR3 = 27;
int PIR4 = 29;
int IIR1 = 22; //Input from Infrared 1
int IIR2 = 24;
int IIR3 = 26;
int IIR4 = 28;
void setup() {
  pinMode(IIR1, INPUT);
  pinMode(IIR2, INPUT);
  pinMode(IIR3, INPUT);
  pinMode(IIR4, INPUT);
  pinMode(PIR1, OUTPUT);
  pinMode(PIR2, OUTPUT);
  pinMode(PIR3, OUTPUT);
  pinMode(PIR4, OUTPUT);
  myservo1.attach(9);
  myservo2.attach(10);
  digitalWrite(PIR1, HIGH);
}

void loop() {
  if (digitalRead(IIR1) == HIGH) {
    for (pos2 = 10; pos2 <= 80; pos2 += 1) { // Head slowly rises
      myservo2.write(pos2);
      delay(30);
    }
  }
  // This if can never execute, since after the above for completed pos2 = 81
  if (pos2 == 80) {
    digitalWrite(PIR1, LOW); // Turn off power to IR 1
    digitalWrite(PIR2, HIGH);
    myservo1.write(25);
  } //Move Head to far right
  //

  if (digitalRead(IIR2) == HIGH){
    for (pos1 = 25; pos1 <= 60; pos1 += 1) { // Move head towards sensor 2
      myservo1.write(pos1);
      delay(30);}
    }
  // Similarly...
  if (pos1 == 60) {
    digitalWrite(PIR2, LOW);//Turn off Power to IR 2
    digitalWrite(PIR3, HIGH);
  }
  // is this “if” meant to be nested inside the preceding “if”??.
  // why is this “if” missing its opening brace?
  if (digitalRead(IIR3) == HIGH)
    for (pos1 = 60; pos1 <= 85; pos1 += 1) { // Turn Head to IR3
      myservo1.write(pos1);
      delay(30);
    }
  // Similarly...
  if (pos1 == 85) {
    digitalWrite(PIR3, LOW); //Turn off Power to IR3
    digitalWrite(PIR4, HIGH);
  }
  // This “if” also missing opening brace
  if (digitalRead(IIR4) == HIGH)
    for (pos1 = 85; pos1 <= 120; pos1 += 1) {
      myservo1.write(pos1);
      delay(30);
    }
  // Similarly...
  if (pos1 == 120) {
    myservo2.write(10);
    myservo1.write(60);
    digitalWrite(PIR4, LOW);
    digitalWrite(PIR1, HIGH);
  }
}

Sorry, I think I must be missing something…
If you want the second “if” statement to execute when the “for” loop completes in the preceding “if” why not just remove the second “if” and place its code after the } which terminates the for loop?

I seriously recommend getting into the habit of ALWAYS following any control statement (if/else/while/for) with a code block { } . When you don’t you can get in a right mess, especially if you don’t indent consistently. Try CTRL-T in the IDE to auto format.

You have something similar to this in three places:

  if (digitalRead(IIR1) == HIGH) {
    for (pos2 = 10; pos2 <= 80; pos2 += 1) { // Head slowly rises
      myservo2.write(pos2);
      delay(30);
    }
  }
  if (pos2 == 80) {

pos2 MUST be 81 at this point, so the “if” statement is unnecessary because the condition is ALWAYS false.

When you are tempted to suffix variable names with numbers, it is time to learn about arrays. Arrays would shorten this code (but not necessarily make it any more clear).

I’d suggest your program is a clear candidate to use a switch - case structure:

It makes the process a LOT clearer than multiple if’s.

Example here

That is just the advice I needed. Thank you to everyone. Just need to know when I need to switch to a different method of programming for my projects.