How can I loop through all colours in code?

Right I need to make a certain part of a material change colour the part in question is called “indicator color” and it needs to loop through the whole colour spectrum so from R-RB-B-BG-G-GR-R-RB etc. I’m very bad with this sort of coding however and I have no idea where to start. I know it requires a lerp but it also needs to loop, any help will be very much appreciated

I’m not quite sure if this is what you are asking for but below is an example to loop through the color spectrum.

Color currentColor;

for(int b = 0; b <= 255; b++)
{
    for(int g = 0; g <= 255; g++)
    {
        for(int r = 0; r <= 255; r++)
        {
            currentColor = new Color(r/255, g/255, b/255);
        }
    }
}

This will loop through all the available colors in an 8 bit color palette. Starting from all red shades then moving towards green to blue in the end. Also the shades will start from darker to lighter as it will start from black and end with white.

If you need specific range then you can actually set values for variables r, g, and b in the loop for specific value range you need.