Issue with sumo robot using 2 IR sensors and 1 ultrasoic sensor

Hello everyone!
i am building a mini sumo robot for a school project. i am using 2 IR sensors (1 placed on the front and on the back ), 1 ultrasonic sensor and 2 dc motors which are contacted to a L298N Dual H-Bridge.
the idea is , or my strategy is when both IR sensor sees the black colour which is the arena colour the robot will start rotating or searching none stop , until the ultrasonic sensor will give a reading which is , if the distance to the object is less than 10cm , the robot should go forward.

the issue is . if you check the code down bellow , where it is written

 while (IR_back > 650 && IR_front > 650 ) { //   > 650 means black color 
    search();
  break;
  }

`
it is actually rotating (searching) nonstop which is what I want , but the issue is when I add this conditions which is

while (IR_back > 650 && IR_front > 650 ) {
    search();
   if (distance < 10 ){
    FORWARD ();
   }
   break;
  }

`
the robot won't rotate anymore and it would just go straight forward even when the distance is more than 10cm .

however all the sensors are working fine when tested separately. including the ultrasonic sensor

any help would mean a lot as i have to submit this project tomorrow and i have been trying for the past two day.

thank you

here is the full code :

#include <Ultrasonic.h>

Ultrasonic ultrasonic(3,4);
int distance ;

#define IR_sensor_front A0 // front sensor
#define IR_sensor_back A1 // rear senson

// motor pins 
const int IN1=5;
const int IN2=6;
const int IN3=9;
const int IN4=10;

void setup() {
  
 delay (5000); // delay for 5 sec when turned on 
 
}

void loop() {
 distance = ultrasonic.read();
 
 int IR_front = analogRead(IR_sensor_front);
 int IR_back = analogRead(IR_sensor_back);

 while (IR_front< 650 ) {
  Stop();
   delay (50);
   BACKWARD();
   delay(500);
  break;
  }
while (IR_back < 650 ) {
  
   Stop();
   delay (50);
   FORWARD();
   delay(500);
  break;
  }
  while (IR_back > 650 && IR_front > 650 ) {
    search();
   if (distance < 10 ){
    FORWARD ();
   }
   break;
  }
}
void FORWARD (){
  analogWrite(IN1,0);
  analogWrite(IN2,255);
  analogWrite(IN3,0);
  analogWrite(IN4,255);
}//--------------------------------------------
void BACKWARD (){
  analogWrite(IN1,255);
  analogWrite(IN2,0);
  analogWrite(IN3,255);
  analogWrite(IN4,0);
}//--------------------------------------------
void Stop(){
  analogWrite(IN1,0);
  analogWrite(IN2,0);
  analogWrite(IN3,0);
  analogWrite(IN4,0);
}//--------------------------------------------
void search(){
  analogWrite(IN1,0);
  analogWrite(IN2,255);
  analogWrite(IN3,255);
  analogWrite(IN4,0);
}

`

Keep in mind that ‘black’ isn’t always what you think it is"

You’re ‘looking’ in the visible spectrum. but the IR sensor isn’t…

I’m guessing you’ll encounter some unexpected problems when this hits the arena.

Good idea and practice, just remember that in science there are often phases of trial and error.

Thank you sir for your replay ,
but the issue isn't with the IR sensors , because it actually works fine , the robot will go back or forward once it sees the white line .
I have also used the digital pins for the IR sensors where the output will be 0 if white or 1 if black. and both works fine.

how about adding a part of the code where if it doesn't find anything in 5-10 seconds the sumo turns off ? if you keep looping while there is nothing close to it with no stopping condition then it'll just spin constantly until it finds something to hit. also, i recommend playing around the echo sensor a bit more to get used to the configuration and its behavior since it has a much greater detection range (i think it has a range of about a meter) so i would also suggest creating a range between 10-20cm, so a while loop is needed. also just a tip instead of using two motors, you can print a differentiator to control the speed of the wheels and use a servo motor to turn it, this will give you a more precise control over the direction it turns.