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

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.