Can I put a While into a If

I am trying to code an algorithm and I wanst expecting to have this trouble...

I'm trying to put a while inside a if..else structure...but the compiler says to me that It was expecting ;

this is my code

void loop(){
   
   Lux = BH1750_Read();
   Serial.print("measurement in lux:");
   Serial.print(Lux);
   if (Lux <= 5000)
   {
   
     T1 = Lux/100;
   }
   else(Lux>5000 && Lux <= 10000)
   {
     while( Lux > 500 && Lux < 5500)
     {
      T1 = 100; 
      }
       T1 = Lux/100;
   }
   Timer1.pwm(LedPin1,T1);
   Timer1.pwm(LedPin2,T1);
  
}

anyone knows what's going on??

I don't see any missing semi-colons, can you give us the whole error message? How is the while condition going to change? (Lux is not modified inside the while body) if you enter the while loop, it will just loop forever.

The problem is that during the while() loop, the vaiables never change anymore.

If, insde the while() loop, Lux doesn't change, you'll never get out of that loop!

Lux ia value for an external sensor light by I2C port...It's changing each 16ms....

My whole code( for the part that matter) is :

long previousMillis = 0;
long interval = 500;


void loop(){
   unsigned long currentMillis = millis();
   Lux = BH1750_Read();
   Serial.print("measurement in lux:");
   Serial.print(Lux);
    Timer1.pwm(LedPin1,T1);
   Timer1.pwm(LedPin2,T1);
    
    if(currentMillis - previousMillis > interval) 
    {

    previousMillis = currentMillis; 
   
   if (Lux <= 5000)
   {
   
     T1 = Lux/100;
   }
   else if(Lux > 5000 && Lux <=10000) 
   {
     while(Lux< 5500){
       T1 = 100;
       }
       T1 = Lux/100;
   }
   else{
     
     T1= 1024;
   }
  }
}

Thank you I fixed that trouble, I didnt remember elseif.....

But know I have a doubt with millis(), It is set to get into that If( the millis if I mean), each 0.5s...but I dont understand what I'll do. would it get into the millis if and for how long It will stay in??just I need that it get a new value to T1...

yes, I know that, but how long time It stays there, because I have a while inside, how many instructions It does??

I mean, If a put a while insede, will it stay there until the while is broken??

while(Lux< 5500){
       T1 = 100;
       }

A while loop runs what is inside over and over again until the condition is no longer true. None of the code outside of the while loop will run, only what is inside the while loop until the condition is not true.

Nothing inside this while loop ever changes the value of Lux and nothing outside of the loop that you might think is changing it can execute until the while loop ends. So if Lux is < 5500 and you enter this loop, nothing will ever make it greater or equal. Therefore, this loop will hang forever and never exit.

Lux is a value that is read by I2C bus, but It's true, to be read It must get the function read and in that way It wont get there ever....could I do the same with an internal if??

In case it's not yet clear, Lux = BH1750_Read(); has to be inside the while statement for LUX to change.

But it will happen a lot faster than every 16 mS!