Is a while loop embedded in if/else if legal?

Is the following legal in Arduino? Thanks.

if (hours == 10)    // Hour 10 - Binary eight & two\
  {
  while (lastColor_8 == randNumber && lastColor_2 == randNumber)  //BINARY 8 & 2
    {
   randNumber = random(11);  // Generate a new (color) randNumber
    }
   currColor_8 = randNumber;
   currColor_2 = randNumber;
   
   lastColor_8 = currColor_8;
   lastColor_2 = currColor_2;
   colorCheck_10();
   ledCheck();                     // Blink without delay
   }                 

else if (hours == 11)                 // Hour 11 -Binary eight, two & one
  {
 while (lastColor_8 == randNumber && lastColor_2 == randNumber && lastColor_1 == randNumber){  //BINARY 8-2-1
    {
  randNumber = random(11);
    }
  currColor_8 = randNumber;
  currColor_2 = randNumber;
  currColor_1 = randNumber;

  lastColor_8 = currColor_8;
  lastColor_2 = currColor_2;
  lastColor_1 = currColor_1;
  colorCheck_11();
  ledCheck();
   }

It is legal syntax. If it is not compiling it is because there is an error somewhere that you have not provided code for.

I am not sure what you are trying to achieve, though, because the same randNumber is being assigned to all your variables. Your loop generates the number a few times but overwrites the variable with each new number.

It is 'legal' but this while loop

  while (lastColor_8 == randNumber && lastColor_2 == randNumber)  //BINARY 8 & 2
    {
   randNumber = random(11);  // Generate a new (color) randNumber
    }

will do nothing unless lastColor_8 and lastColor_2 both happen to equal the already existing value of randNumber when it starts, and even then it will end almost immediately because the condition will become false in most cases straight away.

Can you explain what it is supposed to do and how ?

Thanks for coming back. This is part of a 4 light ( with multiple lights for each digit) Chronodot RTC shield Binary Kaleidoscope Clock like the one on the Chronoart site based on a Microchip PIC. Attached is a jpg explaining how it should work. Each of 11 colors is assigned a number. In this function, I’m trying to determine if the current color of a given digit is different than a new random generated color. If the current color is the same, a new random color is generated until there is a change. This is going to somewhat
complicated in numbers with multiple digits, ie 7, 12 etc. Each digit could have a different color and would need to be tested after each random generation until a suitable new color for all 2 or 3 digits is found. How would one test for this complication? Any thoughts or ideas would be greatly appreciated. Thanks again.

Each digit could have a different color and would need to be tested after each random generation until a suitable new color for all 2 or 3 digits is found.

Test the colour of each digit individually.

while (lastColor_2 == newColor_2)
{
   newColor_2 = random(11);
}

I will say it before anyone else does. There is a much neater way of doing this using arrays to avoid repeating code for each digit but I suggest that you get the tedious 'do each number separately' method working first.

I had thought that using arrays would be a good solution, but at this point, you're absolutely right, I need to get what I have started working, and then, possibly, get into a more complicated but better and neater array set up. Thanks and I'm certain that I will be needing your programming expertise down the line.

get into a more complicated but better and neater array set up.

Using arrays will make your code neater, better, AND less complicated, not more.