I am pretty new to shader programming, and I have read that it is not great to use conditionals in them to have the shader perform different tasks depending on some outside state. Is that true? In most cases or just some?

For example, it seems to me like switching shader programs would be a bigger deal than putting an IF-THEN in the shader, where you are branching on a something for example like

if (mode == GRADIENT_MODE) {
// set vertex color according to gradient
else if (mode == PAINT_MODE) {
// set vertex color to current color

This is just an example and there may be better ways to switch between gradient and flat coloring, but in general, is it bad to have a shader with statements like this? I was just thinking it would be easy to have a more general-purpose vertex shader, where the function is determined by some kind of uniform mode flag.

I am going to try testing it out different ways, but I thought I would ask if it's better in general to switch between a bunch of different shader programs during a render frame, or to have just one or two shaders which branch inside to perform different functions?