light sensing robot not functioning properly

My robot is meant to find the greatest value from 3 sensors mounted on the back, then drive away from the sensor getting the most amount of light
So the sensors are placed one facing the back, and 1 on each back corner

e.g if someone shines a lot of light on the right corner it should turn left… or if someone shines light on the middle sensor it should drive straight

the issue is once my program finds the sensor getting the most light it only drives away from that… so if i start giving another sensor light, it doesn’t affect the robot
how can i fix this?

 //motor A---left
int ENA = 5;
int IN1 = 6;
int IN2 = 7;

//motor B---right
int ENB = 10;
int IN3 = 8;
int IN4 = 9;

//setup motorspeed
int motorspeeda = 100;
int motorspeedb = 140; // robot was veering slightly to the left,, increasing left motor speed makes it drive straight

//define light resistor pins
int resistor1 = A0;
int resistor2 = A2;
int resistor3 = A4;

//setup array
int resVals[]= {0,0,0};

void setup(){

    //initialise pins as outputs
    //pins defualt to input so light resistors don't need to be changed
    pinMode(ENA, OUTPUT);
    pinMode(IN1, OUTPUT);
    pinMode(IN2, OUTPUT);
    pinMode(ENB, OUTPUT);
    pinMode(IN3, OUTPUT);
    pinMode(IN4, OUTPUT);

    // turn serial port on
    Serial.begin(9600);
}
//function for robot to stop
void stop_all(){
    analogWrite(ENA, LOW);
    digitalWrite(IN2, LOW);
    digitalWrite(IN1, LOW);
    analogWrite(ENB, LOW);
    digitalWrite(IN3, LOW);
    digitalWrite(IN4, LOW);
}

//function for robot to go forward
void forward(){
    analogWrite(ENA, motorspeeda);
    digitalWrite(IN2, LOW);
    digitalWrite(IN1, HIGH);
    analogWrite(ENB, motorspeedb);
    digitalWrite(IN3, HIGH);
    digitalWrite(IN4, LOW);
}

//function for robot to go backwards
void backwards(){
    analogWrite(ENA, motorspeeda);
    digitalWrite(IN2, HIGH);
    digitalWrite(IN1, LOW);
    analogWrite(ENB, motorspeedb);
    digitalWrite(IN3, LOW);
    digitalWrite(IN4, HIGH);
}

//function for robot to go right
void turnRight(){
        analogWrite(ENA, motorspeeda);
        digitalWrite(IN2, LOW);
        digitalWrite(IN1, HIGH);
        analogWrite(ENB, motorspeedb);
        digitalWrite(IN3, LOW);
        digitalWrite(IN4, LOW);
}
    
    


//function for robot to go left
void turnLeft(){
    
        analogWrite(ENA, motorspeeda);
        digitalWrite(IN2, HIGH);
        digitalWrite(IN1, LOW);
        analogWrite(ENB, motorspeedb);
        digitalWrite(IN3, LOW);
        digitalWrite(IN4, LOW);
    }
  
  void loop(){
  //read resistor values from pins
  resVals[0]= analogRead(resistor1);
  resVals[1]= analogRead(resistor2);
  resVals[2]= analogRead(resistor3);
  
  //so you can view resistor values
  Serial.print("res0:   ");
  Serial.println(resVals[0]);
  Serial.print("res1:   ");
  Serial.println(resVals[1]);
  Serial.print("res2:   ");
  Serial.println(resVals[2]);


int greatestResVal = 0;

int numOfResistors = 3;
int greatestResistor = 0;
  
for (int i = 0; i < 3; i++){
  if(resVals[i] > greatestResVal){
    greatestResVal = resVals[i];
    greatestResistor = i;}
  }
Serial.println(greatestResistor);
while (greatestResistor == 0){
        turnLeft();}
while( greatestResistor == 1){
      forward();}
while (greatestResistor == 2){
        turnRight();}
    
    
}
  while (greatestResistor == 0) {

turnLeft();
  }

So, while it's turning left, how could the value of greatestResistor get updated?

Try using if() instead of while().