Try it this way:
c1 = thisComp.layer("Null 1").effect("Color 1")("Color");
c2 = thisComp.layer("Null 1").effect("Color 2")("Color");
n = 0;
if (numKeys > 0){
n = nearestKey(time).index;
if (key(n).time > time) n--;
}
if (n == 0){
c1;
}else if (n == numKeys){
c2;
}else{
if (n%2){
linear(time,key(n).time,key(n+1).time,c1,c2);
}else{
linear(time,key(n).time,key(n+1).time,c2,c1);
}
}