I wouldn’t use ifs for this. Material branches are not exactly fast operations. Also, I’m not sure why you’re masking the RG and B channels there. When you take the RGB pins, you’re only getting that channel anyway.
The best way to use a mask is to set up the channels so they only use combinations of colours you can reconstruct easily. That is, colours you can separate back out. Pure R G and B are easy, because you can take the pins directly, but you can also use any combination of 2 channels, by subtracting one from the other. Then, you can multiply these with a colour or texture, and blend them together, like so:
Not only does this avoid using expensive branch operations, but it also allows you to feather your materials more naturally, as you can just about see on the middle mask channel.
P.S. Clamping is quite important, though, as when subtracting, you may get values below 1, which can mess up the final blend.